Skip to content

west: runners: openocd: debug: add log file support#108806

Open
josuah wants to merge 1 commit into
zephyrproject-rtos:mainfrom
josuah:pr_openocd_log
Open

west: runners: openocd: debug: add log file support#108806
josuah wants to merge 1 commit into
zephyrproject-rtos:mainfrom
josuah:pr_openocd_log

Conversation

@josuah
Copy link
Copy Markdown
Contributor

@josuah josuah commented May 9, 2026

Use OpenOCD feature to use a log file instead of printing the logs out, which west does not show.

This permits accessing the OpenOCD logs at all which are not shown otherwise.

$ west debug --log-file asdf.log

-- west debug: rebuilding
ninja: no work to do.
-- west debug: using runner openocd
Using /home/josuah/z/bflb/zephyr/build/zephyr/zephyr.elf
-- runners.openocd: OpenOCD GDB server running on port 3333; no thread info available
GNU gdb (Zephyr SDK 1.0.0) 16.2
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-build_pc-linux-gnu --target=riscv64-zephyr-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://github.com/zephyrproject-rtos/sdk-ng/issues>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/josuah/z/bflb/zephyr/build/zephyr/zephyr.elf...
could not connect: Connection timed out.
The target architecture is set to "riscv:rv32".
(gdb) quit

$ cat asdf.log

DEPRECATED! use 'adapter driver' not 'interface'
adapter speed: 400 kHz

Ready for Remote Connections
Error: unable to find a matching CMSIS-DAP device

cc:

@josuah josuah marked this pull request as ready for review May 9, 2026 22:35
@zephyrbot zephyrbot added the area: West West utility label May 9, 2026
jilaypandya
jilaypandya previously approved these changes May 10, 2026
Comment thread scripts/west_commands/runners/openocd.py
Comment thread scripts/west_commands/runners/openocd.py Outdated
@josuah josuah added the In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on label May 10, 2026
@josuah josuah removed the In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on label May 10, 2026
Use OpenOCD feature to use a log file instead of printing the logs out,
which west does not show. This permits accessing the OpenOCD logs at all
which are not shown otherwise.

Signed-off-by: Josuah Demangeon <me@josuah.net>
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@pdgendt pdgendt left a comment

Choose a reason for hiding this comment

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

I'm surprised the OpenOCD runner doesn't simply support the tool_opt arguments? This would've allowed to pass in any argument to the OpenOCD command.

@josuah
Copy link
Copy Markdown
Contributor Author

josuah commented May 11, 2026

I'm surprised the OpenOCD runner doesn't simply support the tool_opt arguments?

Should there still be an explicit --xxx-file mapping to mirror the --elf-file, --bin-file, --elf-file... found on other runners as a way to homogenize the arguments across utilities?

I can open a new PR or modify the current one, as is best.

@marc-hb
Copy link
Copy Markdown
Contributor

marc-hb commented May 11, 2026

Use OpenOCD feature to use a log file instead of printing the logs out, which west does not show.

Are you saying something somewhere captures OpenOCD logs and then drops them on the floor? That sounds like a serious design bug worth filing. If correct, then this PR is a useful mitigation worth merging but not a fix yet.

At worst, too verbose logs that cannot be turned off should be buried in some log file in some possibly obscure, default location. But never discarded.

@marc-hb
Copy link
Copy Markdown
Contributor

marc-hb commented May 11, 2026

Should there still be an explicit --xxx-file mapping to mirror the --elf-file, --bin-file, --elf-file... found on other runners as a way to homogenize the arguments across utilities?

--bin-file and --elf-file have been deprecated 4 years ago, see #52295 and friends.

Also, I'm afraid I'm missing the connection with this PR.

@josuah
Copy link
Copy Markdown
Contributor Author

josuah commented May 12, 2026

Are you saying something somewhere captures OpenOCD logs and then drops them on the floor? That sounds like a serious design bug worth filing.

Yes, this is probably related to GDB taking over stdio for terminal UI, and OpenOCD "polluting" this with logs. 4d1d8a7

Good for day-to-day use, but difficult for debugging anything.

Also, I'm afraid I'm missing the connection with this PR.

I was only thinking how to have the same "use this file for log output" flag for all runners.

@marc-hb
Copy link
Copy Markdown
Contributor

marc-hb commented May 12, 2026

Yes, this is probably related to GDB taking over stdio for terminal UI, and OpenOCD "polluting" this with logs. 4d1d8a7

Sorry for insisting but you sound like you know more than enough to describe this in a new GH issue. Would you mind? It does not have to be long or "the perfect bug", far from it. Hey, it might even be quickly closed as "too difficult, wontfix" but that would still be a useful place to record this design problem. Then a source comment in this PR pointing at this new issue would be perfect.

self.print_gdbserver_message()

if command in ('attach', 'debug'):
server_proc = self.popen_ignore_int(server_cmd, stderr=subprocess.DEVNULL)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is where the logs are discarded AFAIU

@marc-hb
Copy link
Copy Markdown
Contributor

marc-hb commented May 12, 2026

Thanks @josuah for filing #108961!

After gathering more context, I think these logs should be always redirected to some temporary file. Then, this new --log-file option would only override the default location. git grep -C 5 tempfile -- '**.py' shows how the Zephyr build typically does this.

EDIT: or, it could just be some hardcoded location the build directory. Probably simpler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: West West utility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants