Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gdbstub: fix memory binary upload on latest GDB #15759

Merged
merged 2 commits into from
Feb 9, 2025

Conversation

XuNeo
Copy link
Contributor

@XuNeo XuNeo commented Feb 5, 2025

Summary

GDB release 16.2 recently to fix the incompatibility issue with LLDB.
For us, the only change is stub must report it support feature 'binary-upload' before GDB will use this feature.

For more information, find bug report and discussion in https://sourceware.org/bugzilla/show_bug.cgi?id=32593

Use GDB 16.2, now it works with binary upload.

  [remote] Sending packet: $x39c,4#a7
  [remote] Received Ack
  [remote] Packet received: b\000\203

Impact

Since GDB 16.1 is only alive for a short time, I expect minor impact on user.
Now they should upgrade to GDB 16.2 if previously using 16.1. Failing to do so will have slower memory read just like before 16.1.

Testing

You may need to build GDB 16.2 manually. Follow these steps.

  • Requirements
apt install gcc build-essential texinfo bison flex libpython3-dev python3 libgmp-dev libmpfr-dev libreadline-dev
  • Build GDB
./configure --enable-targets=all --prefix=$HOME/.local --disable-binutils --disable-ld --disable-gold --disable-gas --disable-sim --disable-gprof --disable-gprofng --disable-gcore --without-guile

make
make install

Test using QEMU mps3-an547.

Compile

cmake -Bbuild -GNinja -DBOARD_CONFIG=mps3-an547:gdbstub nuttx
ninja -C build

Run qemu

 qemu-system-arm -M mps3-an547 -m 2G -nographic -kernel build/nuttx -gdb tcp::1127 -serial mon:stdio -serial pty

Notice the redirected pts device in log, like char device redirected to /dev/pts/74 (label serial1).
In this case /dev/pts/74 is the one we are going to use for GDB to connect the stub.

Connect to GDB stub

Current configuration is only to attach GDB stub to serial device only when crash happened by turning off CONFIG_SERIAL_GDBSTUB_AUTO_ATTACH.

So trigger a force panic by input ctrl+/ in nsh.


NuttShell (NSH) NuttX-12.8.0
nsh>
nsh>
nsh>
nsh> dump_assert_info: Current Version: NuttX  12.8.0 e2314d3338d Feb  5 2025 11:47:12 arm
dump_assert_info: Assertion failed Force panic by user.: at file: /drivers/serial/serial.c:2289 task: Idle_Task process: Kernel 0xa8f9

Input y to enter GDB debug mode.

uart_gdbstub_panic_callback: Press Y/y key in 10 seconds to enter gdb debug mode
uart_gdbstub_panic_callback: Enter panic gdbstub mode, plase use gdb connect to debug
uart_gdbstub_panic_callback: Please use gdb of the corresponding architecture to connect to nuttx
uart_gdbstub_panic_callback: such as: arm-none-eabi-gdb nuttx -ex "set target-charset ASCII" -ex "target remote /dev/ttyUSB0"

Now connect to GDB stub

 gdb-multiarch build/nuttx -ex "set debug remote on" -ex "set mem inaccessible-by-default on" -ex "set target-charset ASCII" -ex "target remote /dev/pts/74"

XuNeo added 2 commits February 5, 2025 11:40
GDB release 16.2 recently to fix the incompatibility issue with LLDB.
For us, the only change is stub must report it support feature 'binary-upload' before GDB will use this feature.
For more information, find bug report and discussion in https://sourceware.org/bugzilla/show_bug.cgi?id=32593

Use GDB 16.2, now it works with binary upload.
```
  [remote] Sending packet: $x39c,4#a7
  [remote] Received Ack
  [remote] Packet received: b\000\203
```

Signed-off-by: Neo Xu <[email protected]>
Add this config so we can test GDB stub feature easily.

Signed-off-by: Neo Xu <[email protected]>
@github-actions github-actions bot added Area: OS Components OS Components issues Size: XS The size of the change in this PR is very small labels Feb 5, 2025
@XuNeo XuNeo force-pushed the fix-gdbstub-binary-upload branch from a064422 to e2314d3 Compare February 5, 2025 04:00
@github-actions github-actions bot added Board: arm Size: S The size of the change in this PR is small and removed Size: XS The size of the change in this PR is very small labels Feb 5, 2025
@nuttxpr
Copy link

nuttxpr commented Feb 5, 2025

[Experimental Bot, please feedback here]

Yes, this PR appears to meet the NuttX requirements, although some minor improvements could be made.

Strengths:

  • Clear Summary: The summary explains the "why," "what," and "how" of the change, referencing the upstream bug report.
  • Impact is addressed: The impact on users (requiring a GDB upgrade) is described, along with acknowledging potential performance implications if they don't. Other impacts are implicitly NO, which is acceptable.
  • Testing is documented: Clear steps for building GDB, compiling NuttX, running QEMU, and connecting the debugger are provided. Including example output demonstrating the fix is helpful.

Areas for Improvement:

  • Quantify the Impact: Instead of "minor impact," be more specific. How many users are likely affected? What is the performance difference with/without the fix? Even a rough estimate is better than none.
  • Before/After Logs: The "Testing logs before/after change" sections are used to show specific changes in behavior due to the PR. The current logs show how to use the system, but don't highlight the fix itself. Ideally, show GDB failing with binary upload in 16.1 (before) and succeeding in 16.2 (after).
  • Build Host Details: While you mention build requirements, specify your build host details (OS, CPU, compiler version) more explicitly. For example: "Build Host: Linux (Ubuntu 22.04), x86_64, GCC 11.3.0."
  • Target Details: Be more specific about the target. "QEMU mps3-an547" is good, but add the QEMU version.
  • Consider a simplified test case: If possible, create a small, self-contained test case that reproduces the issue and demonstrates the fix. This would make it easier for reviewers to verify the change. This might not be practical for this specific scenario, but is generally good practice.

Conclusion:

The PR is mostly compliant and provides valuable information. By addressing the minor improvements above, you can strengthen the PR and make it easier for reviewers to understand and accept.

@Jasinsky
Copy link
Contributor

Jasinsky commented Feb 5, 2025

Minor - remove

Note: Please adhere to [Contributing Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).

in PR description

@anchao anchao merged commit 1aced99 into apache:master Feb 9, 2025
39 checks passed
@XuNeo XuNeo deleted the fix-gdbstub-binary-upload branch February 9, 2025 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: OS Components OS Components issues Board: arm Size: S The size of the change in this PR is small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants