
Has anyone managed to use the simulator target in GDB?
I have cross GDB 12.1, configured for arm-eabi. I created a very simple test program, which sets up the stack pointer, jumps to main() and main() just touches some global variables then goes into an infinite loop. The whole thing is linked to address 0. The target CPU is Cortex-M3.
I tell gdb the following:
target sim mem 0 0xbfffffff rw load b main run
Everything looks fine, except that to the run command GDB responds:
Starting program: /tmp/gdbtest/test.abs [Inferior 1 (process 42000) exited normally]
and I get back the prompt. That is, it did not break on main, it did not do anything. If I examine the global vars that main() was supposed to write, they are unchanged, so the program was not run at all.
Is there some magic incantation that I missed? Any help, pointers to some documentation regarding the use of the simulator target would be much appreciated.

The GDB built-in simulator (target sim) only supports a small set of architectures and the Cortex-M is not one of them. Even if your arm-eabi-gdb appears to accept the target sim command, it doesn't mean it can correctly simulate your target CPU. In fact, the simulation will silently do nothing (as you observed), or it may "run" and immediately return as if your program exited.
The GDB simulator only supports a subset of ARM7TDMI and a few classic ARM instruction sets, mostly targeting older ARM processors or A-profile cores, not the ARMv7-M profile used by the Cortex-M series.
I would look at using QEMU, or more preferably, Renode.

Thank you! I did not know that. At least it would be nice if GDB would print a message like "Target CPU not supported" or something.
I looked at QEMU, but what I saw was that it emulates boards, not just cores. For my particular purpose I need a simulation of the core plus memory, but I don't want any OS or specific hardware around the core.
What I actually need is a simulator which can simulate several ARM profiles, at least ARMv7 A/R/M with or without FPU/Neon, ARMv6M and ARMv4T. It is needed to run regression tests on libraries which should work on all of the above but which contain all sorts of target specific hand-crafted routines (including assembly stuff), so while the API of the lib is the same, underneath it is tuned to the relevant ISA and profile. The libs do not talk to HW, they're purely SW, so all I need is a CPU and its attached memory, load the test code, let it go, stop when a specific function is called and tell the regression makefile the result of the particular test. If it can also print to stdout, then great, if it can't, I can live with that. Cycle count helps, but not essential.
Haven't heard of Renode, Will take a look.
Thanks again!

It sounds like Renode would be a good fit for what you're trying to do. Definitely check it out!
