Skip to content

Conversation

multiplemonomials
Copy link
Collaborator

@multiplemonomials multiplemonomials commented Aug 25, 2025

Summary of changes

One issue is that I occasionally get trouble viewing peripheral registers due to the GDB server not "telling" GDB that the peripheral memory is valid memory that exists. So, GDB cannot print peripheral register values in the debugger. This has happened to me enough times that I'd like to fix it permanently by just always allowing GDB to access all memory. As far as I'm aware, there is no downside to enabling that option except that GDB might forward certain invalid accesses to the target (which would, as far as I know, just produce an error on these like normal).

The other issue is more serious: I noticed that ninja debug-<target> was not working on my machine, due to what seems like double-quoting in the gdbinit file.

/path/to/test-mbed-rtos-malloc.gdbinit:4: Error in sourced command file:
"/path/to/test-mbed-rtos-malloc.hex": No such file or directory.

(where the .gdbinit contains):

# connect to GDB server
target remote 127.0.0.1:23331
monitor reset
load \"/path/to/test-mbed-rtos-malloc.hex\"
tbreak main
monitor reset
c

The specified path to test-mbed-rtos-malloc.hex was valid, so I believe the issue is the \" characters causing quotes to be included in the file path.

@ccli8 I'm curious, what conditions did you observe the double quoting being needed? Do you have any objections to me removing it?

Impact of changes

  • set mem inaccessible-by-default off is now the default (at least for GDB servers other than J-Link, which seems to do a better job of this)
  • Command-line debugging error fixed

Migration actions required

Documentation

None


Pull request type

[X] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[X] Tests / results supplied as part of this PR

I am able to debug via the command line after this PR, while I could not before.


@ccli8
Copy link

ccli8 commented Aug 25, 2025

Checking generated .vscode/launch.json, with original \\\", I get "load \"/path/to/foo.hex\"":

"overrideLaunchCommands": ["monitor reset halt", "handle SIGTRAP nostop noprint", "set remotetimeout 30", "load \"/path/to/foo.hex\"", "tbreak main", "monitor reset halt"],

But after change to \", I get "load "/path/to/foo.hex"":

"overrideLaunchCommands": ["monitor reset halt", "handle SIGTRAP nostop noprint", "set remotetimeout 30", "load "/path/to/foo.hex"", "tbreak main", "monitor reset halt"],

Nesting "" causes such error.

@multiplemonomials
Copy link
Collaborator Author

Ah gotcha so it's a VS Code vs command line GDB issue. Gotcha. I will look into it...

Base automatically changed from bugfix/fix-stm32u0-build-error to master August 26, 2025 15:36
@multiplemonomials multiplemonomials force-pushed the bugfix/fix-some-debug-issues branch from b2409bf to 0e77f9e Compare August 28, 2025 15:21
@multiplemonomials
Copy link
Collaborator Author

multiplemonomials commented Aug 28, 2025

ok @ccli8 I updated the VS Code generator to escape the quotes. Tested on my end and looks like it generates valid JSON:

	// Debug launch for target test-mbed-drivers-c-strings.
	{
	    "type": "cortex-debug",
	    "name": "Debug test-mbed-drivers-c-strings LPC1768 Develop",
	    "executable": "/home/jamie/Mbed/mbed-os/build/LPC1768-Develop/drivers/tests/TESTS/mbed_drivers/c_strings/test-mbed-drivers-c-strings.elf",
	    "cwd": "${workspaceRoot}",
	    "gdbPath": "/usr/local/gcc-arm-10.3/bin/arm-none-eabi-gdb",
		"objdumpPath": "/usr/local/gcc-arm/bin/arm-none-eabi-objdump",
		"servertype": "external",
		"gdbTarget": "127.0.0.1:23331",
		"request": "launch",
		"preLaunchTask": "Build test-mbed-drivers-c-strings and start GDB server",
		// Override the command sequences used by VS Code to be correct for this GDB server
		"overrideLaunchCommands": ["monitor reset halt", "handle SIGTRAP nostop noprint", "set remotetimeout 30", "set mem inaccessible-by-default off", "load \"/home/jamie/Mbed/mbed-os/build/LPC1768-Develop/drivers/tests/TESTS/mbed_drivers/c_strings/test-mbed-drivers-c-strings.hex\"", "tbreak main", "monitor reset halt"],
		"overrideRestartCommands": ["monitor reset halt", "monitor gdb_sync", "stepi"],
	},

Copy link

@ccli8 ccli8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test OK on quote escape

@multiplemonomials multiplemonomials merged commit 46c99d4 into master Aug 29, 2025
53 checks passed
@multiplemonomials multiplemonomials deleted the bugfix/fix-some-debug-issues branch August 29, 2025 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants