trungnt2910 / gdb-haiku

GNU General Public License v2.0
2 stars 0 forks source link

Stack trace is not working for non-main thread #2

Closed X547 closed 3 months ago

X547 commented 4 months ago

image

Log: https://gist.github.com/X547/ebd5d3ca9bead35a5519379107c97162

Netbeans project (includes makefile and binaries): MinApp-Netbeans.zip

trungnt2910 commented 4 months ago

Should be fixed at the latest commit.

image

Another bug related to the target mem regions.

X547 commented 4 months ago

gdb-15-haiku-v13 155bd98a6f2

Now it fails to start with sigaction: Invalid Argument. error.

[ 62979] normalize_path("/boot/data/packages/gdb-haiku/install.x86_64/lib/debug", true, 0x7ffb85087460) = 0x0 No error (22 us)
[ 62979] read_stat(0xffffffff, "/boot/data/packages/gdb-haiku/install.x86_64/lib/debug", false, 0x7ffb850873b0, 0x80) = 0x80006003 No such file or directory (19 us)
[ 62979] normalize_path("/boot/home/config/non-packaged/bin/gdb", true, 0x7ffb85087320) = 0x0 No error (22 us)
[ 62979] read_stat(0xffffffff, "/boot/data/packages/gdb-haiku/install.x86_64/bin/gdb", false, 0x7ffb85087270, 0x80) = 0x0 No error (19 us)
[ 62979] read_stat(0xffffffff, "/boot/data/packages/gdb-haiku/install.x86_64/bin/../share/gdb", true, 0x7ffb85087890, 0x80) = 0x0 No error (20 us)
[ 62979] normalize_path("/boot/data/packages/gdb-haiku/install.x86_64/bin/../share/gdb", true, 0x7ffb85087460) = 0x0 No error (22 us)
[ 62979] read_stat(0xffffffff, "/boot/data/packages/gdb-haiku/install.x86_64/share/gdb", false, 0x7ffb850873b0, 0x80) = 0x0 No error (20 us)
[ 62979] set_signal_mask(0x0, (nil), [0x0]) = 0x0 No error (19 us)
[ 62979] sigaction(0x1, (nil), 0x1e28d26c9c0) = 0x0 No error (12 us)
[ 62979] sigaction(0x2, (nil), 0x1e28d26c9e0) = 0x0 No error (11 us)
[ 62979] sigaction(0x3, (nil), 0x1e28d26ca00) = 0x0 No error (11 us)
[ 62979] sigaction(0x4, (nil), 0x1e28d26ca20) = 0x0 No error (11 us)
[ 62979] sigaction(0x5, (nil), 0x1e28d26ca40) = 0x0 No error (11 us)
[ 62979] sigaction(0x6, (nil), 0x1e28d26ca60) = 0x0 No error (12 us)
[ 62979] sigaction(0x7, (nil), 0x1e28d26ca80) = 0x0 No error (11 us)
[ 62979] sigaction(0x8, (nil), 0x1e28d26caa0) = 0x0 No error (11 us)
[ 62979] sigaction(0x9, (nil), 0x1e28d26cac0) = 0x80000005 Invalid Argument (11 us)
sigaction: Invalid Argument.[ 62979] write(0x2, 0xffffffffffffffff, 0x10b316f4a3d8, 0x1c) = 0x1c (17 us)
[ 62979] ioctl(0x2, TCGETA, 0x7ffb85087710, 0x20) = 0x0 No error (13 us)

[ 62979] write(0x2, 0xffffffffffffffff, 0x10b316f4c818, 0x1) = 0x1 (13 us)
[ 62979] ioctl(0x2, TCGETA, 0x7ffb85087710, 0x20) = 0x0 No error (12 us)
[ 62979] exit_team(0x1) (12 us)
X547 commented 4 months ago

https://github.com/trungnt2910/gdb-haiku/blob/155bd98a6f241e8a07239333b25608523e882bb6/gdbsupport/signals-state-save-restore.cc#L51

sigaction(9) -> -2147483643
[WAIT]
res: -1
errno: 2147483643
EINVAL: -2147483643
sigaction: Invalid Argument.

Only one thing can do this. Lets find it...

Bingo! https://github.com/trungnt2910/gdb-haiku/blob/155bd98a6f241e8a07239333b25608523e882bb6/gdb/configure.nat#L502

Footgun fully charged. FIRE!

X547 commented 4 months ago

Cherry-picking https://github.com/trungnt2910/gdb-haiku/commit/155bd98a6f241e8a07239333b25608523e882bb6 to gdb-15-haiku-v12 solves this issue.

trungnt2910 commented 4 months ago

Only one thing can do this. Lets find it...

This is required because parts of GDB assumes positive errno values. https://github.com/trungnt2910/gdb-haiku/issues/4#issuecomment-2266715098

For some reasons, flags for GDB does not propagate to the statically linked gdbsupport components. Therefore, the correct fix is to add CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS" CXXFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS" during the ./configure step for the whole repo: https://github.com/trungnt2910/gdb-haiku/issues/4#issuecomment-2268960309

X547 commented 4 months ago

Therefore, the correct fix is to add CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS" CXXFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS" during the ./configure step for the whole repo:

I tried that, but make execute additional configure scripts that do not inherit settings, so it fails.

trungnt2910 commented 3 months ago

I tried that, but make execute additional configure scripts that do not inherit settings, so it fails.

Just rm -rf * from your build directory and start again.

X547 commented 3 months ago

My current configure script: https://gist.github.com/X547/59995d8e1163f622f46d86451f1e341e.

Where should I put that settings? To environment variables or to ./configure arguments? Should I pass it to make?

waddlesplash commented 3 months ago

Environment variables, as I understand it.

trungnt2910 commented 3 months ago

To environment variables or to ./configure arguments?

Just environment variables.

CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS" CXXFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS" ./configure --whatever-other-args
X547 commented 3 months ago

I managed to build gdb-15-haiku-v13 https://github.com/trungnt2910/gdb-haiku/commit/155bd98a6f241e8a07239333b25608523e882bb6 with positive error codes.

Issue in this ticket is solved, but now it generate a lot of SIGTRAP notifications after triggering breakpoint. You need to click discard and continue button a lot of times. But initial SIGTRAP notification in program relocated is disappeared.