Nim
Nim copied to clipboard
Line info can be wrong in GDB
Nim Version
Nim Compiler Version 2.3.1 [Linux: amd64] Compiled at 2025-02-28 Copyright (c) 2006-2025 by Andreas Rumpf
git hash: 7e8a650729e9434574c46350aece7609e5465253 active boot switches: -d:release
Description
Line info can be off in GDB and point to a different line. Basic example
proc foo() =
let x = @[1, 2, 3]
echo x[4]
# Shows here instead
foo()
Compiling that and breaking with b sysFatal it says the line that caused the error is the comment and not the array access line.
Current Output
(gdb) where
#0 _ZN6system8sysFatalE8typeDescIN10exceptions11IndexDefectEE4sinkI6stringE (message_p1="index 4 not in 0 .. 2") at /home/user/.choosenim/toolchains/nim-hashdevel/lib/system/fatal.nim:52
#1 0x000055555556227e in raiseIndexError2 (i_p0=i_p0@entry=4, n_p1=n_p1@entry=2) at /home/user/.choosenim/toolchains/nim-hashdevel/lib/system/chcks.nim:28
#2 0x0000555555562da3 in _ZN4test3fooE () at /home/user/Documents/projects/Nim/test.nim:4
#3 0x0000555555562e75 in NimMainModule () at /home/user/Documents/projects/Nim/test.nim:5
#4 0x0000555555562eaf in NimMainInner () at /home/user/Documents/projects/Nim/test.nim:25
#5 0x0000555555562ec2 in NimMain () at /home/user/Documents/projects/Nim/test.nim:31
#6 0x0000555555562ee4 in main (argc=<optimized out>, args=<optimized out>, env=<optimized out>) at /home/user/Documents/projects/Nim/test.nim:39
Expected Output
(gdb) where
#0 _ZN6system8sysFatalE8typeDescIN10exceptions11IndexDefectEE4sinkI6stringE (message_p1="index 4 not in 0 .. 2") at /home/user/.choosenim/toolchains/nim-hashdevel/lib/system/fatal.nim:52
#1 0x000055555556227e in raiseIndexError2 (i_p0=i_p0@entry=4, n_p1=n_p1@entry=2) at /home/user/.choosenim/toolchains/nim-hashdevel/lib/system/chcks.nim:28
#2 0x0000555555562da3 in _ZN4test3fooE () at /home/user/Documents/projects/Nim/test.nim:3
#3 0x0000555555562e75 in NimMainModule () at /home/user/Documents/projects/Nim/test.nim:5
#4 0x0000555555562eaf in NimMainInner () at /home/user/Documents/projects/Nim/test.nim:25
#5 0x0000555555562ec2 in NimMain () at /home/user/Documents/projects/Nim/test.nim:31
#6 0x0000555555562ee4 in main (argc=<optimized out>, args=<optimized out>, env=<optimized out>) at /home/user/Documents/projects/Nim/test.nim:39
Known Workarounds
No response
Additional Information
Looking at the #line docs it says "Subsequent lines are counted from linenum.". When looking at the c source we see
#line 1401 FX_279
nimlf_(1401, "/home/user/Documents/projects/Nim/compiler/semexprs.nim");if (nimAddInt(s, ((NI) 1), (&TM__rF9caJawfOjYTjsgLVUSGFA_3216))) {
raiseOverflow();
so fix I am assuming is to add #line 0 to the lines after?