-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[Needs testing] Add full gdb support with uart/Serial integration #4386
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
Conversation
@kylefleming are you aware of PR #4336 ? |
@devyte #4336 adds another copy of gdbstub configured with different settings, while this PR integrates Arduino-specific UART handling into gdbstub so that they can coexist. I like this approach a lot. However sometimes the full gdb stub (which would include run control debugging support) is not needed, and there is not enough IRAM to include it. So it would be nice if there was still an option to include the smaller panic-handler-only gbd stub. |
(Edit: @igrr beat me to it) @devyte Yep, I'm aware of it. The code that's being added in #4336 is actually just a near copy of the GDBStub code already in Esp8266Arduino. #4336 enables the rest of the GDBStub flags, which were previously deemed incompatible with HardwareSerial and Esp8266Arduino's uart library (as noted in this comment). Unfortunately, the GDBStub added with #4336 still maintains that incompatibility. This PR fixes that by rewriting GDBStub in an attempt to be 100% compatible with Esp8266Arduino. Documentation and tutorials still seem like a great contribution though, which is what I believe #4336 is really contributing. The tutorial will likely need to be revised though since this PR simplifies the process quite a bit. |
@igrr Good point about having the option to only include the exception handler. How do you suggest users integrate each version? I'm not familiar with how technical users of this library are. Is adding a build flag to enable the full version something that we can reasonably expect of them? Also, is there any sort of DEBUG flag that would be included if Arduino, Sloeber, PlatformIO, etc were compiling in order to run in debug mode with the debugger attached? |
I would try to implement this choice (full or panic-only gdb stub) using two header files, for example GDBStub.h and GDBStubDebug.h. In GDBStubDebug.h, there would be a non-static function declared, for example: extern "C" void gdbstub_all_features_hook() {
extern "C" void gdbstub_all_features();
gdbstub_all_features();
} In gdbstub source, there is a weak definition of
Putting it all together, if GDBStub.h is included into the sketch, That's quite a hack, but on the other hand it's very easy to use and does not depend on IDE specific features. Does this make sense to you? |
Yep, makes sense. Does the build script skip compiling and linking the "full debug source" compilation unit if it's not being referenced from the sketch? My initial assumption was that it linked everything in the library. |
Hmm, you're right — this is only going to work if the GDBStub library is first packaged into an archive file. Then the object file will not be included into the output unless it resolves some of the undefined symbols. However Arduino IDE does not build an archive file for each library, so that's not going to work. Let me think of some other option. |
@igrr I understand that it's different settings, which is why I mentioned at some point that the two PRs don't seem mutually exclusive to me (in answer to @freeck's concerns about his efforts). |
@devyte I appreciate the concern to not have wasted efforts. There aren't multiple competing implementations at this point, don't worry. There're only 2 versions: the original GDBStub that Espressif wrote (both the version currently in Esp8266Arduino and the one included in PR #4336 are basically the same as this original one) and the new reworked one that is the content of this PR. What @freeck is contributing in #4336 is documentation on how to use the one written by Espressif. Some of that documentation will still be valid and some of it will be obsolete, which is what @freeck's comment was pointing out. This PR is an improvement on the original implementation, so it's a good thing that the process is simplified and we no longer need quite so extensive documentation. |
@igrr it looks like this gdbstub takes up around 3.7k of ram. Theoretically, there wouldn't be much of a difference between the panic-only version and the full version since most of the space is being taken up by packet reading/building and gdb command response logic, which both versions would require. The main 2 differences between the 2 versions are that the full version requires uart hooking logic and the fact that monitoring uart at all times requires the packet deconstruction code to be able to operate asynchronously. Reading asynchronously takes up more code, but doesn't necessarily need to take up that much more than a synchronous version. If I optimized the library, is there a size that would be acceptable to include the full version by default? |
@kylefleming I totally agree with @igrr that your version is the ultimate one, I dont see any reason to keep "my version" on github. Some of the documentation is perhaps reuseable. |
Has there been progress in reducing that 3.7K? |
@devyte @kylefleming I got it working using the Sloeber IDE using arduino-esp V2.4.0-rc2 (btw, the latest version takes 500 bytes IRAM extra!). One issue: when you change GDBSTUB_REDIRECT_OUTPUT 1 to 0 the compilation fails. |
@freeck will you be able to share the new work on this? PR? What are the plans to get this into the main branch? |
@weswitt No problem, but lets first wait for the comments of @kylefleming concerning my proposed modifications... or use the files published on #4336 |
@kylefleming This is a very interesting PR! But, it looks like the build is failing due to warnings (== error) in the sources. Can you try rebuilding locally, but using the "File->Preferences->Compiler Warnings->All" option? That'll show the same errors the build is reporting (as the CI requires -Wall to be clean). |
@earlephilhower I had the same problem compiling with Sloeber/Eclipse-IDE. The sections seem to interfere, I got "dangerous relocation errors"..... |
@freeck it's not even getting to the link stage here. The compiler is showing many unused parameters and variables, which makes the core -Wall -Werror compile fail:
Simple code edits, assuming these variables are consciously intended not to be used, can fix this (i.e. adding "(void) xxx;" for unused params, deleting locals which aren't used, etc.). |
@earlephilhower I do not use the Arduino-IDE for application development, but the Sloeber-IDE. I am afraid you have to wait for @kylefleming to respond....sorry.
|
Sure, I got that @freeck. But for the Arduino core, PRs need to compile cleanly w/-Wall -Werror, which is the (very minor!) problem here. @kylefleming needs to do some minor tweaks and then we can worry about moving between IRAM and IROM on this setup. |
@earlephilhower I understand, But for me reducing IRAM was a major issue as debugging medium to large applications is almost impossible with this version of gdbstub...... |
Hello, guys! Please take a look at #4480. We've found an unexpected behaviour of assert(0) without GDB stub. I think you should definitely consider testing this case here |
821f545
to
d9316d8
Compare
Thanks all for the feedback. I've taken another pass at this. Changes:
Note: Requires #4356 to work properly I think the main remaining issue is the code size. Obviously, we could move everything to flash, as a few people have suggested, but then we lose the ability to use gdb at all during periods when the icache is disabled (whether an exception was thrown, a breakpoint was placed, or ctrl-c interrupt was sent). @igrr Do you have any further thoughts on this? |
a9a1a22
to
b405881
Compare
More improvements:
I also created an example repo. It uses platformio for setup, but the The example can be found here: |
@igrr I had another thought. Could we check for a disabled cache and re-enable it? When execution continues, it could be re-disabled. It looks like If we went this route, only the wrapper function would need to be in iram, alleviating the size concern. |
Good idea, i think it should work, and might also be used in the non-GDB
panic handler.
…On Fri, Mar 16, 2018 at 1:33 PM, Kyle Fleming ***@***.***> wrote:
@igrr <https://github.com/igrr> I had another thought. Could we check for
a disabled cache and re-enable it? When execution continues, it could be
re-disabled.
It looks like Cache_Read_Enable_2 and Cache_Read_Disable_2 serve this
function. These are the methods the spi functions use. I'm not sure what
would need to be flushed though. Possibly a few extw or isync
instructions would be enough.
If we went this route, only the wrapper function would need to be in iram,
alleviating the size concern.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4386 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AEJcenv_3VVHyU2SxAxe1qw6tI6M8WB8ks5te060gaJpZM4SKHl_>
.
|
@kylefleming there are conflicts in this pr now. Could you please resolve? |
Closing in favor of #5559 . |
Summary
This adds full gdb debugging support, including integration with
HardwareSerial
and Esp8266Arduino'suart
library.Note: This will need some testing to make sure it can be added to any sketch without any side effects until the user wants to debug with gdb.
Dependencies
This PR requires #4356 to work properly.
Features
#include <GDBStub.h>
in order to enableCode changes
attached
command to signal that gdb connected to a running program and should detach instead of kill when disconnectingGDBSTUB_REDIRECT_CONSOLE_OUTPUT
andGDBSTUB_CTRLC_BREAK
flags by default, since those should now be compatible with the rest of the Esp8266Arduino library.Running gdb
Create a file containing the following gdb initial commands (adjust your target and baudrate if needed):
Run gdb:
PlatformIO support
platform-espressif8266/boards/d1_mini.json
)and then set
debug_port
in yourplatformio.ini
. For example: