Knowledge

Stack trace

Source 📝

75:. Technically, once a block of memory has been allocated on the stack, it cannot be easily removed as there can be other blocks of memory that were allocated before it. Each time a function is called in a program, a block of memory called an 69:. Memory is continuously allocated on a stack but not on a heap, thus reflective of their names. Stack also refers to a programming construct, thus to differentiate it, this stack is referred to as the program's 79:
is allocated on top of the call stack. Generally, the activation record stores the function's arguments and local variables. What exactly it contains and how it's laid out is determined by the
882:
optimizations can replace one stack frame with another, and frame pointer elimination can prevent call stack analysis tools from correctly interpreting the contents of the call stack.
416:, which was in turn called by the code on line 15 (the last line) of the program. The activation records for each of these three functions would be arranged in a stack such that the 101:
called - up to the point where the stack trace is generated. In a post-mortem scenario this extends up to the function where the failure occurred (but was not necessarily caused).
1092:
are "recoverable" and can be handled gracefully. However, recoverable errors cannot generate a stack trace as they are manually added and not a result of a runtime error.
874:
provide this functionality. In these languages, some compiler optimizations may interfere with the call stack information that can be recovered at runtime. For instance,
1543: 1397: 1088:
are "unrecoverable" and the current thread will become poisoned experiencing stack unwinding. Functions that return a
62: 1498: 118: 1447: 161: 1422: 1096: 1081: 433: 114: 133:
has no built-in support for doing this, but C++ users can retrieve stack traces with (for example) the
1474: 1353: 17: 1085: 855: 871: 1522: 299:
Running the program under the standard Python interpreter produces the following error message.
1026:, stack traces can be dumped manually by printing the value returned by static member function 1099:
has experimental support for stack traces on unrecoverable errors. Rust supports printing to
1107: 66: 8: 1318: 137: 121:, have built-in support for retrieving the current stack trace via system calls. Before 1591: 1328: 145: 80: 1402:
Java Platform Standard Edition & Java Development Kit Version 16 API Specification
1113:
When enabled, such backtraces look similar to below, with the most recent call first.
1561: 608:
The exception lists functions in descending order, so the most-inner call is first.
1375: 875: 58: 31: 61:. When a program is run, memory is often dynamically allocated in two places: the 98: 1323: 866:) do not have native support for obtaining stack traces, but libraries such as 1585: 867: 91: 86:
Programmers commonly use stack tracing during interactive and post-mortem
889:
function returns an output with the program function and memory address.
54: 1333: 141: 71: 1313: 879: 134: 102: 87: 38: 152:
property that contain the stack from the place where it was thrown.
1023: 863: 130: 1100: 859: 1103:
when a thread panics, but it must be enabled by setting the
400:
The stack trace shows where the error occurs, namely in the
90:. End-users may see a stack trace displayed as part of an 1523:"Working Draft, Standard for Programming Language C++" 1084:
has two types of errors. Functions that use the panic
420:
function would occupy the bottom of the stack and the
57:
at a certain point in time during the execution of a
30:"Backtrace" redirects here. For the 2018 film, see 1469: 1467: 94:, which the user can then report to a programmer. 1376:"traceback — Print or retrieve a stack traceback" 125:was added in standard library as a container for 1583: 1464: 27:Report of stack frames during program execution 97:A stack trace allows tracking the sequence of 424:function would occupy the top of the stack. 436:, stack traces can be dumped manually with 1423:"Environment.StackTrace Property (System)" 14: 1584: 113:Many programming languages, including 1532:. ISO/IEC. 2021-10-23. p. 766. 395:name 'error' is not defined 108: 24: 1398:"Thread (Java SE 16 & JDK 16)" 304:Traceback (most recent call last): 25: 1603: 404:function. It also shows that the 1475:"Backtraces (The GNU C Library)" 878:can cause missing stack frames, 105:do not appear in a stack trace. 1554: 1544:"rustonomicon unwinding - Rust" 1536: 1515: 1491: 1448:"Thread (Java Platform SE 8 )" 1440: 1415: 1390: 1368: 1346: 13: 1: 1339: 160:As an example, the following 849: 53:) is a report of the active 7: 1307: 164:program contains an error. 10: 1608: 1499:"Getting Started - 1.76.0" 1028:std::stacktrace::current() 440:Take the following input: 29: 1354:"libc manual: backtraces" 155: 1115: 1032: 891: 610: 442: 301: 166: 1562:"std::backtrace - Rust" 1076: 427: 408:function was called by 412:, which was called by 885:For example, glibc's 127:std::stacktrace_entry 1251:rust_panic_with_hook 1108:environment variable 1319:Context (computing) 1090:std::result::Result 72:function call stack 1329:Exception handling 438:Thread.dumpStack() 81:calling convention 1566:doc.rust-lang.org 1548:doc.rust-lang.org 1095:As of June 2021, 990:__libc_start_main 374:"tb.py" 356:"tb.py" 326:"tb.py" 308:"tb.py" 77:activation record 16:(Redirected from 1599: 1576: 1575: 1573: 1572: 1558: 1552: 1551: 1540: 1534: 1533: 1527: 1519: 1513: 1512: 1510: 1509: 1495: 1489: 1488: 1486: 1485: 1471: 1462: 1461: 1459: 1458: 1444: 1438: 1437: 1435: 1434: 1419: 1413: 1412: 1410: 1409: 1394: 1388: 1387: 1385: 1383: 1372: 1366: 1365: 1363: 1361: 1350: 1303: 1300: 1297: 1293: 1289: 1285: 1282: 1278: 1274: 1270: 1267: 1263: 1259: 1255: 1252: 1248: 1244: 1240: 1237: 1233: 1229: 1225: 1222: 1219: 1216: 1212: 1208: 1204: 1200: 1197: 1196:unwind_backtrace 1193: 1189: 1185: 1181: 1177: 1173: 1169: 1165: 1162: 1159: 1155: 1152: 1149: 1146: 1143: 1140: 1139:execute_to_panic 1137: 1134: 1131: 1128: 1125: 1122: 1119: 1106: 1091: 1072: 1069: 1066: 1063: 1060: 1057: 1054: 1051: 1048: 1045: 1042: 1039: 1036: 1029: 1018: 1015: 1012: 1009: 1006: 1003: 1000: 997: 994: 991: 988: 985: 982: 979: 976: 973: 970: 967: 964: 961: 958: 955: 952: 949: 946: 943: 940: 937: 934: 931: 928: 925: 922: 919: 916: 913: 910: 907: 904: 901: 898: 895: 888: 845: 842: 839: 836: 833: 830: 827: 824: 821: 818: 815: 812: 809: 806: 803: 800: 797: 794: 791: 788: 785: 782: 779: 776: 773: 770: 767: 764: 761: 758: 755: 752: 749: 746: 743: 740: 737: 734: 731: 728: 725: 722: 719: 716: 713: 710: 707: 704: 701: 698: 695: 692: 689: 686: 683: 680: 677: 674: 671: 668: 665: 662: 659: 656: 653: 650: 647: 644: 641: 638: 635: 632: 629: 626: 623: 620: 617: 614: 604: 601: 598: 597: 594: 591: 588: 584: 581: 578: 575: 572: 569: 566: 565: 562: 558: 555: 552: 549: 546: 543: 540: 537: 534: 531: 528: 525: 522: 519: 516: 515: 512: 508: 505: 502: 499: 496: 493: 490: 489: 486: 482: 479: 476: 473: 470: 467: 464: 461: 458: 455: 452: 449: 446: 439: 423: 419: 415: 411: 407: 403: 396: 392: 389: 386: 383: 379: 375: 371: 368: 365: 361: 357: 353: 350: 347: 344: 341: 338: 335: 331: 327: 323: 320: 317: 313: 309: 305: 295: 294: 291: 287: 286: 283: 279: 276: 273: 270: 267: 264: 261: 258: 257: 254: 250: 247: 244: 241: 238: 235: 232: 229: 226: 223: 220: 217: 214: 211: 208: 205: 204: 201: 198: 195: 192: 189: 185: 182: 179: 176: 173: 170: 151: 128: 124: 109:Language support 99:nested functions 32:Backtrace (film) 21: 1607: 1606: 1602: 1601: 1600: 1598: 1597: 1596: 1582: 1581: 1580: 1579: 1570: 1568: 1560: 1559: 1555: 1542: 1541: 1537: 1525: 1521: 1520: 1516: 1507: 1505: 1497: 1496: 1492: 1483: 1481: 1473: 1472: 1465: 1456: 1454: 1452:docs.oracle.com 1446: 1445: 1441: 1432: 1430: 1421: 1420: 1416: 1407: 1405: 1396: 1395: 1391: 1381: 1379: 1374: 1373: 1369: 1359: 1357: 1352: 1351: 1347: 1342: 1310: 1305: 1304: 1301: 1298: 1295: 1291: 1287: 1283: 1280: 1276: 1272: 1268: 1265: 1261: 1257: 1253: 1250: 1246: 1242: 1238: 1235: 1231: 1227: 1223: 1220: 1217: 1214: 1210: 1206: 1202: 1198: 1195: 1191: 1187: 1183: 1179: 1175: 1171: 1167: 1163: 1160: 1157: 1153: 1150: 1147: 1144: 1141: 1138: 1135: 1132: 1129: 1126: 1123: 1120: 1117: 1104: 1089: 1079: 1074: 1073: 1070: 1067: 1064: 1061: 1058: 1055: 1052: 1049: 1046: 1043: 1040: 1037: 1034: 1027: 1020: 1019: 1016: 1013: 1010: 1007: 1004: 1001: 998: 995: 992: 989: 986: 983: 980: 977: 974: 971: 968: 965: 962: 959: 956: 953: 950: 947: 944: 941: 938: 935: 932: 929: 926: 923: 920: 917: 914: 911: 908: 905: 902: 899: 896: 893: 886: 852: 847: 846: 843: 840: 837: 834: 831: 828: 825: 822: 819: 816: 813: 810: 807: 804: 801: 798: 795: 792: 789: 786: 783: 780: 777: 774: 771: 768: 765: 762: 759: 756: 753: 750: 747: 744: 741: 738: 735: 732: 729: 726: 723: 720: 717: 714: 711: 708: 705: 702: 699: 696: 693: 690: 687: 684: 681: 678: 675: 672: 669: 666: 663: 660: 657: 654: 651: 648: 645: 642: 639: 636: 633: 630: 627: 624: 621: 618: 615: 612: 606: 605: 602: 599: 595: 592: 589: 586: 585: 582: 579: 576: 573: 570: 567: 563: 560: 559: 556: 553: 550: 547: 544: 541: 538: 535: 532: 529: 526: 523: 520: 517: 513: 510: 509: 506: 503: 500: 497: 494: 491: 487: 484: 483: 480: 477: 474: 471: 468: 465: 462: 459: 456: 453: 450: 447: 444: 437: 430: 421: 417: 413: 409: 405: 401: 398: 397: 394: 390: 387: 384: 381: 377: 373: 369: 366: 363: 359: 355: 351: 348: 345: 342: 339: 336: 333: 329: 325: 321: 318: 315: 311: 307: 303: 297: 296: 292: 289: 288: 284: 281: 280: 277: 274: 271: 268: 265: 262: 259: 255: 252: 251: 248: 245: 242: 239: 236: 233: 230: 227: 224: 221: 218: 215: 212: 209: 206: 202: 199: 196: 193: 190: 187: 186: 183: 180: 177: 174: 171: 168: 158: 149: 126: 123:std::stacktrace 122: 111: 51:stack traceback 47:stack backtrace 35: 28: 23: 22: 15: 12: 11: 5: 1605: 1595: 1594: 1578: 1577: 1553: 1535: 1514: 1490: 1463: 1439: 1427:Microsoft Docs 1414: 1389: 1367: 1344: 1343: 1341: 1338: 1337: 1336: 1331: 1326: 1324:Stack overflow 1321: 1316: 1309: 1306: 1116: 1105:RUST_BACKTRACE 1078: 1075: 1033: 892: 851: 848: 611: 443: 429: 426: 316:<module> 302: 167: 157: 154: 110: 107: 26: 9: 6: 4: 3: 2: 1604: 1593: 1590: 1589: 1587: 1567: 1563: 1557: 1549: 1545: 1539: 1531: 1524: 1518: 1504: 1503:www.boost.org 1500: 1494: 1480: 1476: 1470: 1468: 1453: 1449: 1443: 1428: 1424: 1418: 1403: 1399: 1393: 1377: 1371: 1355: 1349: 1345: 1335: 1332: 1330: 1327: 1325: 1322: 1320: 1317: 1315: 1312: 1311: 1114: 1111: 1109: 1102: 1098: 1093: 1087: 1083: 1031: 1025: 890: 883: 881: 877: 873: 869: 865: 861: 857: 609: 441: 435: 425: 300: 165: 163: 153: 147: 143: 139: 136: 132: 120: 116: 106: 104: 103:Sibling calls 100: 95: 93: 92:error message 89: 84: 82: 78: 74: 73: 68: 64: 60: 56: 52: 48: 45:(also called 44: 40: 33: 19: 1569:. Retrieved 1565: 1556: 1547: 1538: 1530:open-std.org 1529: 1517: 1506:. Retrieved 1502: 1493: 1482:. Retrieved 1478: 1455:. Retrieved 1451: 1442: 1431:. Retrieved 1429:. 2021-05-07 1426: 1417: 1406:. Retrieved 1404:. 2021-03-04 1401: 1392: 1380:. Retrieved 1378:. python.org 1370: 1358:. Retrieved 1348: 1236:default_hook 1211:default_hook 1112: 1094: 1080: 1068:'\n' 1021: 884: 853: 607: 431: 399: 298: 159: 112: 96: 85: 76: 70: 55:stack frames 50: 46: 42: 36: 1479:www.gnu.org 1266:begin_panic 887:backtrace() 43:stack trace 1571:2021-06-15 1508:2021-06-15 1484:2021-06-15 1457:2021-06-15 1433:2021-07-04 1408:2021-07-04 1340:References 1334:Call stack 1053:stacktrace 146:exceptions 142:JavaScript 135:stacktrace 1592:Debugging 1356:. gnu.org 1314:Tail call 1292:task_impl 1277:task_impl 1262:panicking 1247:panicking 1232:panicking 1207:panicking 1184:backtrace 1164:backtrace 880:tail call 850:C and C++ 658:dumpStack 625:Exception 593:dumpStack 391:NameError 88:debugging 39:computing 18:Backtrace 1586:Category 1308:See also 1130:panicked 1065:<< 1044:<< 876:inlining 65:and the 1288:futures 1273:futures 1218:closure 1188:tracing 1059:current 376:, line 358:, line 328:, line 310:, line 148:hold a 138:library 59:program 1382:8 July 1360:8 July 1118:thread 1101:stderr 1022:As of 957:x86_64 664:Thread 652:Thread 587:Thread 571:static 545:static 521:static 495:static 472:String 460:static 457:public 445:public 260:return 207:return 162:Python 156:Python 129:, pre- 1526:(PDF) 1166:: 1161:stack 1142:' 1136:' 1127:' 1121:' 1086:macro 1024:C++23 963:linux 872:boost 868:glibc 864:C++23 862:(pre- 854:Both 757:demo1 724:demo2 691:demo3 634:trace 631:Stack 577:demo3 561:demo3 551:demo2 536:demo2 527:demo1 511:demo1 448:class 385:error 380:, in 372:File 362:, in 354:File 332:, in 324:File 314:, in 306:File 282:error 150:stack 140:. In 131:C++23 63:stack 1384:2014 1362:2014 1296:park 1281:with 1148:main 1124:main 1097:Rust 1082:Rust 1077:Rust 1041:cout 996:0xf5 975:libc 870:and 858:and 835:java 829:Main 823:main 817:Main 802:java 796:Main 790:demo 784:Main 769:java 763:Main 751:Main 736:java 730:Main 718:Main 703:java 697:Main 685:Main 676:1336 670:java 646:lang 640:java 619:lang 613:java 574:void 548:void 524:void 501:demo 498:void 485:demo 475:args 466:main 463:void 451:Main 434:Java 428:Java 117:and 115:Java 67:heap 41:, a 1258:std 1243:std 1228:std 1203:std 1192:imp 1180:imp 1176:sys 1172:std 1047:std 1035:std 1014:out 969:gnu 951:lib 942:out 924:out 906:out 860:C++ 596:(); 564:(); 539:(); 514:(); 488:(); 432:In 278:(): 272:def 213:def 175:(): 169:def 49:or 37:In 1588:: 1564:. 1546:. 1528:. 1501:. 1477:. 1466:^ 1450:. 1425:. 1400:. 1299:.. 1294::: 1290::: 1286:: 1279::: 1275::: 1271:: 1264::: 1260::: 1256:: 1249::: 1245::: 1241:: 1234::: 1230::: 1226:: 1221:}} 1215:{{ 1213::: 1209::: 1205::: 1201:: 1194::: 1190::: 1186::: 1182::: 1178::: 1174::: 1170:: 1154:rs 1133:at 1110:. 1062:() 1056::: 1050::: 1038::: 1030:: 1017:() 984:.6 981:so 945:() 927:() 909:() 814:at 781:at 748:at 742:12 715:at 709:15 682:at 637:at 580:() 554:() 530:() 504:() 393:: 388:() 378:13 370:() 322:() 312:15 293:() 285:() 256:() 243:== 237:if 225:): 144:, 119:C# 83:. 1574:. 1550:. 1511:. 1487:. 1460:. 1436:. 1411:. 1386:. 1364:. 1302:. 1284:6 1269:5 1254:4 1239:3 1224:2 1199:1 1168:0 1158:3 1156:: 1151:. 1145:, 1071:; 1011:. 1008:a 1005:/ 1002:. 999:) 993:+ 987:( 978:. 972:/ 966:- 960:- 954:/ 948:/ 939:. 936:a 933:/ 930:. 921:. 918:a 915:/ 912:. 903:. 900:a 897:/ 894:. 856:C 844:) 841:3 838:: 832:. 826:( 820:. 811:) 808:6 805:: 799:. 793:( 787:. 778:) 775:9 772:: 766:. 760:( 754:. 745:) 739:: 733:. 727:( 721:. 712:) 706:: 700:. 694:( 688:. 679:) 673:: 667:. 661:( 655:. 649:. 643:. 628:: 622:. 616:. 603:} 600:} 590:. 583:{ 568:} 557:{ 542:} 533:{ 518:} 507:{ 492:} 481:{ 478:) 469:( 454:{ 422:c 418:a 414:a 410:b 406:c 402:c 382:c 367:c 364:b 360:9 352:) 349:i 346:( 343:b 340:= 337:j 334:a 330:3 319:a 290:a 275:c 269:z 266:+ 263:k 253:c 249:: 246:0 240:z 234:5 231:= 228:k 222:z 219:( 216:b 210:j 203:) 200:i 197:( 194:b 191:= 188:j 184:0 181:= 178:i 172:a 34:. 20:)

Index

Backtrace
Backtrace (film)
computing
stack frames
program
stack
heap
function call stack
calling convention
debugging
error message
nested functions
Sibling calls
Java
C#
C++23
stacktrace
library
JavaScript
exceptions
Python
Java
C
C++
C++23
glibc
boost
inlining
tail call
C++23

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.