Skip to content

don't reattach last target on connect #1390

@tlyu

Description

@tlyu

With current firmware, the BMP reattaches the most recently attached target when GDB connects to it. I think it should wait until explicitly instructed to attach. Among other things, the official documentation says that connecting using target extended-remote in GDB won't attach the target or perform any SWD or JTAG actions. (see https://black-magic.org/usage/gdb-commands.html#connecting-gdb-to-the-black-magic-probe)

I found this to be particularly annoying when configuring VS Code's debugger support to use BMP. I ended up having to write a custom GDB script to test whether connecting to the probe had caused a side effect of reattaching to the target, and if so, skip the scan and attach. (The scan detaches the reattached target, which causes VS Code to think that the target program has exited, and VS Code then exits gdb.)

I discovered this was happening due to the qXfer:features and qXfer:memory-map commands that are sent by GDB at connect time. I tried some local changes to look up the relevant information in the last_target structure without reattaching the target, and they appear to work.

I think it's debatable whether it's even correct to do those lookups on the previous target, instead of returning an error, because the user might have changed the device under test to a different type of target without resetting the BMP. On the other hand, it might be reasonable to run GDB commands that invoke those queries after detaching a target; I'm not sure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugConfirmed bugGDBIssue/PR related to GDB

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions