7
31
Fork
You've already forked blackmagic
23

Fix "New Inferior 2" bug with gdb 10-12 #2193

Open
ALTracer wants to merge 2 commits from ALTracer/fix/gdb-10-12-thread into main
pull from: ALTracer/fix/gdb-10-12-thread
merge into: blackmagic-debug:main
blackmagic-debug:main
blackmagic-debug:feature/bmda-remote-comms
blackmagic-debug:ALTracer/feature/aarch64-ident
blackmagic-debug:feature/better-meson-optimisation-handling
blackmagic-debug:feature/am335x-support
blackmagic-debug:feature/esp32-c3-support
blackmagic-debug:feature/cortex-ar-software-breakpoints
blackmagic-debug:feature/unit-testing
blackmagic-debug:feature/windows-usb-serial-interface-naming
blackmagic-debug:fix/bmp-external-spi
blackmagic-debug:ALTracer/feature/bluepillplus-platform
blackmagic-debug:ALTracer/feature/at32f43x-unrdp
blackmagic-debug:feature/const-correctness
blackmagic-debug:ALTracer/feature/fault_handlers
blackmagic-debug:ALTracer/feature/hazard3-ice40-support
blackmagic-debug:fix/ci-cleanup
blackmagic-debug:ALTracer/feature/blackpill-f4-adc
blackmagic-debug:ALTracer/fix/cortex-desc-allocfail-report
blackmagic-debug:ALTracer/feature/spi-perf
blackmagic-debug:ALTracer/feature/calibrate_swd
blackmagic-debug:ALTracer/feature/blank-check
blackmagic-debug:feature/avr
blackmagic-debug:v2.0
blackmagic-debug:v1.9
blackmagic-debug:v1.10
blackmagic-debug:v1.8
ALTracer commented 2026年02月10日 18:36:32 +01:00 (Migrated from github.com)
Copy link

Detailed description

  • Not a new feature.
  • The existing problem is broken debugging with gdb versions 10 through 12 since PR2010, see #2112.
  • This PR solves it by expanding RSP halt-responses and thread info from 1 to p1.1 form aka ppid.tid

Tested against single-core targets like AT32F403A and STM32F411 from BMDA/FT2232H and BMP/blackpill-f411ce. AT32IDE shipped with gdb-10 was affected, and in general some Eclipse CDT-based IDE with old release toolchains for arm-none-eabi.
Untested against multi-core targets like RP2.
Please test this on different gdb versions, probably lldb, and multi-hart (e.g. Cortex-A MPCore), as I don't have well-founded confirmation for a fix like this and why p1.1 is better than 1.

Your checklist for this pull request

Closing issues

Fixes #2112.

## Detailed description * Not a new feature. * The existing problem is broken debugging with gdb versions 10 through 12 since PR2010, see #2112. * This PR solves it by expanding RSP halt-responses and thread info from `1` to `p1.1` form aka p`pid`.`tid` Tested against single-core targets like AT32F403A and STM32F411 from BMDA/FT2232H and BMP/blackpill-f411ce. AT32IDE shipped with gdb-10 was affected, and in general some Eclipse CDT-based IDE with old release toolchains for arm-none-eabi. Untested against multi-core targets like RP2. Please test this on different gdb versions, probably lldb, and multi-hart (e.g. Cortex-A MPCore), as I don't have well-founded confirmation for a fix like this and why p1.1 is better than 1. ## Your checklist for this pull request * [x] I've read the [Code of Conduct](https://github.com/blackmagic-debug/blackmagic/blob/main/CODE_OF_CONDUCT.md) * [x] I've read the [guidelines for contributing](https://github.com/blackmagic-debug/blackmagic/blob/main/CONTRIBUTING.md) to this repository * [x] It builds for hardware native (see [Building the firmware](https://github.com/blackmagic-debug/blackmagic?tab=readme-ov-file#building-black-magic-debug-firmware)) * [x] It builds as BMDA (see [Building the BMDA](https://github.com/blackmagic-debug/blackmagic?tab=readme-ov-file#building-black-magic-debug-app)) * [x] I've tested it to the best of my ability * [x] My commit messages provide a useful short description of what the commits do ## Closing issues Fixes #2112.
ALTracer commented 2026年02月10日 19:53:29 +01:00 (Migrated from github.com)
Copy link

GDB 15.1-1ubuntu2 (which I compiled locally) segfaults spectactularly upon trying to attach to second core of RP2040. Do not merge.

(gdb) det
Detaching from program: /home/altracer/flash.hex, Remote target
[remote] Sending packet: $D#44
[remote] Packet received: OK
[Inferior 1 (Remote target) detached]
(gdb) info threads
[remote] Sending packet: $qfThreadInfo#bb
[remote] Packet received: l
No threads.
(gdb) att 2
Attaching to program: /home/altracer/git/flash.hex, Remote target
[remote] Sending packet: $vAttach;2#38
[remote] Packet received: T05thread:p1.1;
[remote] Sending packet: $qC#b4
[remote] Packet received: QCp1.1
Fatal signal: Segmentation Fault
----- Backtrace ----- 
0x513e28 gdb_internal_backtrace_1
 ./gdb/bt-utils.c:121
0x513e28 _Z22gdb_internal_backtracev
 ./gdb/bt-utils.c:167
0x513e28 _Z22gdb_internal_backtracev
 ./gdb/bt-utils.c:153
0x617e00 handle_fatal_signal
 ./gdb/event-top.c:916
0x617fea handle_sigsegv
 ./gdb/event-top.c:989
0x75510be4251f ???
 ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x8f7796 _ZNKSt8__detail18_Mod_range_hashingclEmm
 /usr/include/c++/11/bits/hashtable_policy.h:430
0x8f7796 _ZNKSt8__detail15_Hash_code_baseI6ptid_tSt4pairIKS1_P11thread_infoENS_10_Select1stESt4hashIS1_ENS_18_Mod_range_hashingENS_20_Default_ranged_hashELb1EE15_M_bucket_indexEmm
 /usr/include/c++/11/bits/hashtable_policy.h:1233
0x8f7796 _ZNKSt10_HashtableI6ptid_tSt4pairIKS0_P11thread_infoESaIS5_ENSt8__detail10_Select1stESt8equal_toIS0_ESt4hashIS0_ENS7_18_Mod_range_hashingENS7_20_Default_ranged_hashENS7_20_Prime_rehash_policyENS7_17_Hashtable_traitsILb1ELb0ELb1EEEE15_M_bucket_indexEm
 /usr/include/c++/11/bits/hashtable.h:795 
0x8f7796 _ZNSt10_HashtableI6ptid_tSt4pairIKS0_P11thread_infoESaIS5_ENSt8__detail10_Select1stESt8equal_toIS0_ESt4hashIS0_ENS7_18_Mod_range_hashingENS7_20_Default_ranged_hashENS7_20_Prime_rehash_policyENS7_17_Hashtable_traitsILb1ELb0ELb1EEEE4findERS2_
 /usr/include/c++/11/bits/hashtable.h:1594
0x8f7796 _ZNSt13unordered_mapI6ptid_tP11thread_infoSt4hashIS0_ESt8equal_toIS0_ESaISt4pairIKS0_S2_EEE4findERS8_
 /usr/include/c++/11/bits/unordered_map.h:869
0x8f7796 _ZN8inferior11find_threadE6ptid_t
 ./gdb/inferior.c:251
0x8f7796 _Z17add_thread_silentP22process_stratum_target6ptid_t
 ./gdb/thread.c:310
0x7ed854 _ZN13remote_target17remote_add_threadE6ptid_tbbb
 ./gdb/remote.c:2905
0x7f2cb0 _ZN22extended_remote_target6attachEPKci
 ./gdb/remote.c:6647
0x6963d4 _Z14attach_commandPKci
 ./gdb/infcmd.c:2643
0x54ca84 _Z8cmd_funcP16cmd_list_elementPKci
 ./gdb/cli/cli-decode.c:2741
0x905f00 _Z15execute_commandPKci
 ./gdb/top.c:569
0x61daff _Z15command_handlerPKc
 ./gdb/event-top.c:579
0x61dba1 _Z20command_line_handlerOSt10unique_ptrIcN3gdb13xfree_deleterIcEEE
 ./gdb/event-top.c:815
0x617984 gdb_rl_callback_handler
 ./gdb/event-top.c:271
0x75510d32ce0d ???
0x61cdaa gdb_rl_callback_read_char_wrapper_noexcept
 ./gdb/event-top.c:196
0x61cf90 gdb_rl_callback_read_char_wrapper
 ./gdb/event-top.c:235
0x933d5f stdin_event_handler
 ./gdb/ui.c:154
0xb7837d gdb_wait_for_event
 ../gdbsupport/./gdbsupport/event-loop.cc:672
0xb7837d gdb_wait_for_event
 ../gdbsupport/./gdbsupport/event-loop.cc:563
0xbea60f _Z16gdb_do_one_eventi.constprop.0
 ../gdbsupport/./gdbsupport/event-loop.cc:263
0x6f6c64 start_event_loop
 ./gdb/main.c:400
0x6f6c64 captured_command_loop
 ./gdb/main.c:464
0x448534 captured_main
 ./gdb/main.c:1337
0x448534 _Z8gdb_mainP18captured_main_args
 ./gdb/main.c:1356
0x448534 main
 ./gdb/gdb.c:38
---------------------
A fatal error internal to GDB has been detected, further
debugging is not possible. GDB will now terminate.
This is a bug, please report it. For instructions, see:
<https://www.gnu.org/software/gdb/bugs/>.

Compare to BMDA on main:

(gdb) att 2
Attaching to program: /home/altracer/flash.hex, Remote target
[remote] Sending packet: $vAttach;2#38
[remote] Packet received: T05thread:1;
[remote] packet_ok: Packet vAttach (attach) is supported
[remote] Sending packet: $qC#b4
[remote] Packet received: QC1
[remote] Sending packet: $Hg1#e0
[remote] Packet received: OK
[remote] Sending packet: $qXfer:features:read:target.xml:0,3fb#46
...
[remote] Sending packet: $qXfer:features:read:target.xml:455,3fb#b4
[remote] Packet received: l
[remote] wait: enter
[remote] wait: exit
[remote] Sending packet: $g#67
[remote] Packet received: 0A00000002000000FFFFFFFFFFFFFFFF000000D0800100008101000000ED00E0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF001F04205D0100008401000000000001001F0420FCFFFFFF00000000
[remote] Sending packet: $qfThreadInfo#bb
[remote] Packet received: m1
[remote] Sending packet: $qsThreadInfo#c8
[remote] Packet received: l
[remote] Sending packet: $qXfer:memory-map:read::0,3fb#e5
[remote] Packet received: m<memory-map><memory type="ram" start="0x20000000" length="0x42000"/><memory type="flash" start="0x10000000" length="0x1000000"><property name="blocksize">0x1000</property></memory></memory-map>
[remote] Sending packet: $qXfer:memory-map:read::c1,3fb#49
[remote] Packet received: l

I don't think reporting thread-id 1 for core 2 is perfect, but reporting pid 1 probably crashes gdb, should be pid 2 thread 1?

GDB 15.1-1ubuntu2 (which I compiled locally) segfaults spectactularly upon trying to attach to second core of RP2040. Do not merge. ``` (gdb) det Detaching from program: /home/altracer/flash.hex, Remote target [remote] Sending packet: $D#44 [remote] Packet received: OK [Inferior 1 (Remote target) detached] (gdb) info threads [remote] Sending packet: $qfThreadInfo#bb [remote] Packet received: l No threads. (gdb) att 2 Attaching to program: /home/altracer/git/flash.hex, Remote target [remote] Sending packet: $vAttach;2#38 [remote] Packet received: T05thread:p1.1; [remote] Sending packet: $qC#b4 [remote] Packet received: QCp1.1 Fatal signal: Segmentation Fault ----- Backtrace ----- 0x513e28 gdb_internal_backtrace_1 ./gdb/bt-utils.c:121 0x513e28 _Z22gdb_internal_backtracev ./gdb/bt-utils.c:167 0x513e28 _Z22gdb_internal_backtracev ./gdb/bt-utils.c:153 0x617e00 handle_fatal_signal ./gdb/event-top.c:916 0x617fea handle_sigsegv ./gdb/event-top.c:989 0x75510be4251f ??? ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0 0x8f7796 _ZNKSt8__detail18_Mod_range_hashingclEmm /usr/include/c++/11/bits/hashtable_policy.h:430 0x8f7796 _ZNKSt8__detail15_Hash_code_baseI6ptid_tSt4pairIKS1_P11thread_infoENS_10_Select1stESt4hashIS1_ENS_18_Mod_range_hashingENS_20_Default_ranged_hashELb1EE15_M_bucket_indexEmm /usr/include/c++/11/bits/hashtable_policy.h:1233 0x8f7796 _ZNKSt10_HashtableI6ptid_tSt4pairIKS0_P11thread_infoESaIS5_ENSt8__detail10_Select1stESt8equal_toIS0_ESt4hashIS0_ENS7_18_Mod_range_hashingENS7_20_Default_ranged_hashENS7_20_Prime_rehash_policyENS7_17_Hashtable_traitsILb1ELb0ELb1EEEE15_M_bucket_indexEm /usr/include/c++/11/bits/hashtable.h:795 0x8f7796 _ZNSt10_HashtableI6ptid_tSt4pairIKS0_P11thread_infoESaIS5_ENSt8__detail10_Select1stESt8equal_toIS0_ESt4hashIS0_ENS7_18_Mod_range_hashingENS7_20_Default_ranged_hashENS7_20_Prime_rehash_policyENS7_17_Hashtable_traitsILb1ELb0ELb1EEEE4findERS2_ /usr/include/c++/11/bits/hashtable.h:1594 0x8f7796 _ZNSt13unordered_mapI6ptid_tP11thread_infoSt4hashIS0_ESt8equal_toIS0_ESaISt4pairIKS0_S2_EEE4findERS8_ /usr/include/c++/11/bits/unordered_map.h:869 0x8f7796 _ZN8inferior11find_threadE6ptid_t ./gdb/inferior.c:251 0x8f7796 _Z17add_thread_silentP22process_stratum_target6ptid_t ./gdb/thread.c:310 0x7ed854 _ZN13remote_target17remote_add_threadE6ptid_tbbb ./gdb/remote.c:2905 0x7f2cb0 _ZN22extended_remote_target6attachEPKci ./gdb/remote.c:6647 0x6963d4 _Z14attach_commandPKci ./gdb/infcmd.c:2643 0x54ca84 _Z8cmd_funcP16cmd_list_elementPKci ./gdb/cli/cli-decode.c:2741 0x905f00 _Z15execute_commandPKci ./gdb/top.c:569 0x61daff _Z15command_handlerPKc ./gdb/event-top.c:579 0x61dba1 _Z20command_line_handlerOSt10unique_ptrIcN3gdb13xfree_deleterIcEEE ./gdb/event-top.c:815 0x617984 gdb_rl_callback_handler ./gdb/event-top.c:271 0x75510d32ce0d ??? 0x61cdaa gdb_rl_callback_read_char_wrapper_noexcept ./gdb/event-top.c:196 0x61cf90 gdb_rl_callback_read_char_wrapper ./gdb/event-top.c:235 0x933d5f stdin_event_handler ./gdb/ui.c:154 0xb7837d gdb_wait_for_event ../gdbsupport/./gdbsupport/event-loop.cc:672 0xb7837d gdb_wait_for_event ../gdbsupport/./gdbsupport/event-loop.cc:563 0xbea60f _Z16gdb_do_one_eventi.constprop.0 ../gdbsupport/./gdbsupport/event-loop.cc:263 0x6f6c64 start_event_loop ./gdb/main.c:400 0x6f6c64 captured_command_loop ./gdb/main.c:464 0x448534 captured_main ./gdb/main.c:1337 0x448534 _Z8gdb_mainP18captured_main_args ./gdb/main.c:1356 0x448534 main ./gdb/gdb.c:38 --------------------- A fatal error internal to GDB has been detected, further debugging is not possible. GDB will now terminate. This is a bug, please report it. For instructions, see: <https://www.gnu.org/software/gdb/bugs/>. ``` Compare to BMDA on `main`: ``` (gdb) att 2 Attaching to program: /home/altracer/flash.hex, Remote target [remote] Sending packet: $vAttach;2#38 [remote] Packet received: T05thread:1; [remote] packet_ok: Packet vAttach (attach) is supported [remote] Sending packet: $qC#b4 [remote] Packet received: QC1 [remote] Sending packet: $Hg1#e0 [remote] Packet received: OK [remote] Sending packet: $qXfer:features:read:target.xml:0,3fb#46 ... [remote] Sending packet: $qXfer:features:read:target.xml:455,3fb#b4 [remote] Packet received: l [remote] wait: enter [remote] wait: exit [remote] Sending packet: $g#67 [remote] Packet received: 0A00000002000000FFFFFFFFFFFFFFFF000000D0800100008101000000ED00E0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF001F04205D0100008401000000000001001F0420FCFFFFFF00000000 [remote] Sending packet: $qfThreadInfo#bb [remote] Packet received: m1 [remote] Sending packet: $qsThreadInfo#c8 [remote] Packet received: l [remote] Sending packet: $qXfer:memory-map:read::0,3fb#e5 [remote] Packet received: m<memory-map><memory type="ram" start="0x20000000" length="0x42000"/><memory type="flash" start="0x10000000" length="0x1000000"><property name="blocksize">0x1000</property></memory></memory-map> [remote] Sending packet: $qXfer:memory-map:read::c1,3fb#49 [remote] Packet received: l ``` I don't think reporting thread-id 1 for core 2 is perfect, but reporting pid 1 probably crashes gdb, should be pid 2 thread 1?
dragonmux force-pushed ALTracer/fix/gdb-10-12-thread from a7c58c9416 to fc36cb24a4
Some checks failed
ci/woodpecker/pr/build-firmware/3 Pipeline was successful
ci/woodpecker/pr/build-firmware/6 Pipeline was successful
ci/woodpecker/pr/build-firmware/1 Pipeline was successful
ci/woodpecker/pr/build-firmware/2 Pipeline was successful
ci/woodpecker/pr/build-firmware/4 Pipeline was successful
ci/woodpecker/pr/build-firmware/5 Pipeline was successful
ci/woodpecker/pr/build-firmware/12 Pipeline was successful
ci/woodpecker/pr/build-firmware/10 Pipeline was successful
ci/woodpecker/pr/build-firmware/11 Pipeline was successful
ci/woodpecker/pr/build-firmware/7 Pipeline was successful
ci/woodpecker/pr/build-firmware/8 Pipeline was successful
ci/woodpecker/pr/build-firmware/9 Pipeline was successful
ci/woodpecker/pr/build-firmware/18 Pipeline failed
ci/woodpecker/pr/build-firmware/15 Pipeline was successful
ci/woodpecker/pr/build-firmware/13 Pipeline was successful
ci/woodpecker/pr/build-firmware/16 Pipeline was successful
ci/woodpecker/pr/build-firmware/17 Pipeline was successful
ci/woodpecker/pr/build-firmware/14 Pipeline was successful
ci/woodpecker/pr/build-linux/1 Pipeline was successful
ci/woodpecker/pr/build-firmware/19 Pipeline was successful
ci/woodpecker/pr/build-firmware/20 Pipeline was successful
ci/woodpecker/pr/build-linux/2 Pipeline was successful
ci/woodpecker/pr/build-windows Pipeline was successful
2026年04月08日 16:37:51 +02:00
Compare
Some checks are pending
ci/woodpecker/pr/build-firmware/3 Pipeline was successful
ci/woodpecker/pr/build-firmware/6 Pipeline was successful
Required
Details
ci/woodpecker/pr/build-firmware/1 Pipeline was successful
ci/woodpecker/pr/build-firmware/2 Pipeline was successful
ci/woodpecker/pr/build-firmware/4 Pipeline was successful
ci/woodpecker/pr/build-firmware/5 Pipeline was successful
ci/woodpecker/pr/build-firmware/12 Pipeline was successful
ci/woodpecker/pr/build-firmware/10 Pipeline was successful
ci/woodpecker/pr/build-firmware/11 Pipeline was successful
ci/woodpecker/pr/build-firmware/7 Pipeline was successful
ci/woodpecker/pr/build-firmware/8 Pipeline was successful
ci/woodpecker/pr/build-firmware/9 Pipeline was successful
ci/woodpecker/pr/build-firmware/18 Pipeline failed
ci/woodpecker/pr/build-firmware/15 Pipeline was successful
ci/woodpecker/pr/build-firmware/13 Pipeline was successful
ci/woodpecker/pr/build-firmware/16 Pipeline was successful
ci/woodpecker/pr/build-firmware/17 Pipeline was successful
ci/woodpecker/pr/build-firmware/14 Pipeline was successful
ci/woodpecker/pr/build-linux/1 Pipeline was successful
Required
Details
ci/woodpecker/pr/build-firmware/19 Pipeline was successful
ci/woodpecker/pr/build-firmware/20 Pipeline was successful
ci/woodpecker/pr/build-linux/2 Pipeline was successful
ci/woodpecker/pr/build-windows Pipeline was successful
Required
Details
ci/woodpecker/pr/lint
Required
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin ALTracer/fix/gdb-10-12-thread:ALTracer/fix/gdb-10-12-thread
git switch ALTracer/fix/gdb-10-12-thread
Sign in to join this conversation.
No reviewers
Labels
Clear labels
BMD App
Black Magic Debug App (aka. PC hosted) (not firmware)
BMP Firmware
Black Magic Probe Firmware (not PC hosted software)
Bug
Confirmed bug
Build system
Build system
Can't reproduce
Maintainers can't reproduce this problem
CI
Continuous Integration System
Contribution wanted
User contributions welcome
Documentation
Project documentation
Draft
Work in progress draft
Duplicate
This issue or pull request already exists
Enhancement
General project improvement
Feedback wanted
Requires additional submitter feedback
Foreign Host Board
Non Native hardware to runing Black Magic firmware on
GDB
Issue/PR related to GDB
Good first issue
Good for newcommers
HwIssue Mitigation
Solving or mitigating a Hardware issue in Software
Information Needed
Maintainers need more information
NativeHardware
Official Black Magic Debug Hardware
New Host Board
New hardware to run Black Magic firmware on
New Target
New debug target
Off Topic
Something that does not involve the project in any way
Potential Bug
A potential, unconfirmed or very special circumstance bug
Regression
Bug caused by a regression
User Interest Needed
More user interest required before consideration
User Testing Needed
Looking for user testing reports
Won't fix
Outside of the project scope or works as intended
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
blackmagic-debug/blackmagic!2193
Reference in a new issue
blackmagic-debug/blackmagic
No description provided.
Delete branch "ALTracer/fix/gdb-10-12-thread"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?