views:

37

answers:

1

Hi

I'm trying to create a little unit test with gdb, for a embedded mcu that is controlled by OpenOCD (that gives me control over my target via a gdb server).

So I would like to automate this with some basic scripting of gdb, but it is not really working.

I would like to write some kind of script for gdb that more or less does this:

  1. Add a couple of breakpoints
  2. Start the program
  3. When we stop, where did it stop (get the frame info)
  4. Quit.

Any ideas?

Thanks Johan


Note:

Let's say that we have this basic structure, that more or less goes into test_failed() or test_success() depending on what the function start_test() returns.

void test_failed() {    
    while(1);    
}

void test_success() {    
    while(1);    
}

int main(void) {    
    int status = start_test();    

    if( status > 0 ) {    
        test_failed();    
    }    
    test_success();

    while(1);    
}

To do this manually in gdb is very strait forward,

(gdb) break test_success
Breakpoint 1 at 0x20: file src/main.c, line 9.
(gdb) break test_failed
Breakpoint 2 at 0x18: file src/main.c, line 5.
(gdb) cont
Continuing.

Breakpoint 1, test_success () at src/main.c:9
9       while(1);
(gdb) frame
#0  test_success () at src/main.c:9
9       while(1);
(gdb) 

So the next step I tried was to add those gdb commands into a gdb startup script that more or less just looked like this.

break test_success
break test_failed
cont 
frame

and start it with

arm-none-eabi-gdb --batch --command=commands.gdb --eval-command="target remote localhost:3333" main.elf

And then I get this back.

Breakpoint 1 at 0x20: file src/main.c, line 9.
Breakpoint 2 at 0x18: file src/main.c, line 5.
/home/cj/MetodikTest/stm32/test-suite/res/commands.gdb:3: Error in sourced command file:
The program is not being run.
main () at src/main.c:13
13  int main(void) {

Where the part that has to do with "cont" is interesting, since I get the a error back from gdb telling be that "The program is not being run". So apparently he tries to run this command to early when before the target is ready...

A: 

OK, I found the answer while asking the question... and it and it was a really simple thing.

You should not use both the "--command" and the "--eval" at the same time if you expect them to be executed in a specific order!

A more predicable way is to put everything in the commands.gdb file and ignore --eval.

So it becomes something like this:

arm-none-eabi-gdb --batch --command=commands.gdb main.elf

Where commands.gdb looks like this:

break test_success
break test_failed
target remote localhost:3333
cont 
frame
Johan