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

Add ARM Cortex-M OpenOCD arch, command, and session manager #83

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Grazfather
Copy link
Collaborator

@Grazfather Grazfather commented Nov 8, 2022

This is for debugging ARM cortex-m targets through JTAG/SWD using the gdbserver implemented in OpenOCD.

Manually tested with a debugger and openocd

archs/ARMOpenOCD.py Outdated Show resolved Hide resolved
archs/ARMOpenOCD.py Outdated Show resolved Hide resolved
@hugsy hugsy changed the base branch from dev to main August 6, 2023 16:39
@Grazfather Grazfather changed the title Add ARMOpenOCD arch Add ARM Cortex-M OpenOCD & BlackMagicProbe arches Aug 24, 2023
Copy link
Owner

@hugsy hugsy left a comment

Choose a reason for hiding this comment

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

LGTM

@Grazfather
Copy link
Collaborator Author

Still needs work, mostly in the gef project, but want to have a way for an arch to hint to the memory manager how to map.

@Grazfather Grazfather mentioned this pull request Dec 13, 2023
1 task
@Grazfather Grazfather force-pushed the add_arm_openocd branch 2 times, most recently from 17f762b to e5123db Compare January 26, 2024 19:42
@hugsy
Copy link
Owner

hugsy commented Jan 30, 2024

Does this PR still make sense (after #99 got merged)?

@Grazfather Grazfather changed the title Add ARM Cortex-M OpenOCD & BlackMagicProbe arches Add ARM Cortex-M OpenOCD arch, command, and session manager Jan 31, 2024
@Grazfather
Copy link
Collaborator Author

Does this PR still make sense (after #99 got merged)?

Yes. That was for BlackMagicProbe, this is for OpenOCD. Updated the description so it makes sense.

Still need to do more testing and write docs.

hugsy
hugsy previously requested changes Feb 16, 2024
Copy link
Owner

@hugsy hugsy left a comment

Choose a reason for hiding this comment

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

very cool stuff, too bad I can't test it I'd love to try but the code is sound (very minor stuff to fix)

archs/arm-blackmagicprobe.py Outdated Show resolved Hide resolved
archs/arm-openocd.py Show resolved Hide resolved
archs/arm-openocd.py Show resolved Hide resolved
archs/arm-openocd.py Outdated Show resolved Hide resolved
docs/commands/gef-openocd-remote.md Outdated Show resolved Hide resolved
archs/arm-openocd.py Outdated Show resolved Hide resolved
archs/arm-openocd.py Outdated Show resolved Hide resolved
@PowerUser64
Copy link

PowerUser64 commented Oct 16, 2024

I tested this on a Tiva C-series (ek-tm4c123gxl) through openocd and everything seems to work fine. LGTM?

Co-authored-by: crazy hugsy <[email protected]>
@Grazfather Grazfather requested a review from hugsy October 18, 2024 23:02
@Grazfather
Copy link
Collaborator Author

@PowerUser64 thanks for testing this out. I just applied what should be a no-op change as suggested by @hugsy . Any chance you could try to ensure it still works? We can merge then. I just don't have the hardware accessible for a few days and I basically forgot this PR was still open, so it would be nice to merge.

@PowerUser64
Copy link

PowerUser64 commented Oct 19, 2024

Seems to work! I'm able to place (hardware) breakpoints, go to next instructions, watch variables (done by halting pc every frame), and I get registers, stack, code, threads, and trace from gef's data printout. Would you like me to test loading arm-openocd.py in any way other than source ./arm-openocd.py, then arch set armopenocd after gef-extras is loaded? (Or is that the intended way?)

@Grazfather
Copy link
Collaborator Author

Ah, you should use the gef-openocd-remote which also sets up the remote. How were you connecting to the target?

@PowerUser64
Copy link

I've been using this command to start openocd and connect to the board:

gef -ex 'target extended-remote | openocd -f board/ek-tm4c1294xl.cfg -c "gdb_port pipe; log_output openocd.log"; monitor reset; monitor halt' ./build/debug.axf

Using gef-openocd-remote, I get an error:

# *first, launched openocd from another terminal like this: openocd -f board/ti_ek-tm4c123gxl.cfg
# ...
gef> gef-openocd-remote localhost 3333
0x0000048e in SystemInit () at src/system_TM4C123.c:608608         for (i = 0; i < 10000; i++);   /* wait a while */
[*] Using `target remote` with GEF should work in most cases, but use `gef-remote` if you can. You can disable the overwrite of the `target remote` command by toggling `gef.disable_target_remote_overwrite` in the config.
[!] Command 'gef-openocd-remote' failed to execute properly, reason: Specified arch ARMOPENOCD is not supported 

In the error, it looks like it's capitalizing the architecture name. When I use arch set, I give it armopenocd in lowercase, but the error it's upper case.

However, I'm also noticing that I don't get the gef-openocd-remote command until after I do source ./arm-openocd.py, so it could be something with my environment. I feel like gef-extras should be loading this by default, along with the other "extra" things that it definitely is loading, but it seems extra arches are unloaded by default. I checked the docs to see if it says how to load these, but I couldn't seem to find anything suggesting a way to automatically load it. Does gef provide a way to load files like arm-openocd.py other than putting source /path/to/gef-extras/archs/arm-openocd.py in ~/.gdbinit?

@Grazfather
Copy link
Collaborator Author

I manually source mine after gef.py and the rest of gef-extras. The arch selection should not be case sensitive. I can't repro this (without hardware atm) but will test with hardware this week.

If what you have is working, that's great! I've never seen the gdb_port pipe openocd command before.

@Grazfather
Copy link
Collaborator Author

I finally had a use for this, and saw that lower case issue.

Pushed a fix in hugsy/gef#1159

@Grazfather
Copy link
Collaborator Author

Should be ok to merge after that PR.

@Grazfather
Copy link
Collaborator Author

I can't merge for some reason

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

Successfully merging this pull request may close these issues.

4 participants