Check in Trace 32 on which CPU breakpoint stopped - trace32

Does anyone knows if that is possible to check ID of CPU on which I reached breakpoint?
I want to print it out and resume execution immediately, so likely need a t32 cmd or global variable.

You get the currently active core number with PRACTICE function CORE() e.g. like this
PRINT CORE()
while you can always execute a command when you hit a breakpoint with the /CMD option of the Break.Set command:
Break.Set <addr> /CMD "<TRACE32 command>"
Putting both together you get
Break.Set 0x10000 /CMD "PRINT ""Core "" CORE() "" stopped at "" PP()"
Note: In TRACE32 double-quotes are escaped with double-quotes. Function PP() returns the current program counter. If you want to restart you core immediately add option /RESUME to Break.Set.

Related

Is it possible to register commands to a breakpoint from within an external file in GDB?

GDB allows registering a set of commands to a specific breakpoint via commands NUM syntax. I need to register the set of commands for a specific breakpoint via an external file, by using a syntax something like the following:
commands ./main.c:18
silent
print buffer[0]
cont
end
commands ./io.c:29
silent
printf "Hello world %i\n", myvar1
cont
end
The commands path/to/file:XX syntax is made up by me. Because the NUM in commands NUM syntax requires exactly the breakpoint's runtime ID number (assigned by GDB), I can not use a deterministic syntax for that purpose.
I'm currently registering breakpoints via a text file with such a content:
break ./main.c:18
break ./io.c:29
and then issuing source breakpoints.txt command inside GDB. It seems that there is no way to register commands at the same time while registering a breakpoint:
(gdb) help break
Set breakpoint at specified line or function.
break [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]
PROBE_MODIFIER shall be present if the command is to be placed in a
probe point. Accepted values are -probe' (for a generic, automatically guessed probe type), -probe-stap' (for a SystemTap probe) or
`-probe-dtrace' (for a DTrace probe).
LOCATION may be a line number, function name, or "*" and an address.
If a line number is specified, break at start of code for that line.
If a function is specified, break at start of code for that function.
If an address is specified, break at that exact address.
With no LOCATION, uses current execution address of the selected
stack frame. This is useful for breaking on return to a stack frame.
THREADNUM is the number from "info threads".
CONDITION is a boolean expression.
Multiple breakpoints at one place are permitted, and useful if their
conditions are different.
Question
Is there any easy way to set some predetermined commands for a predetermined breakpoint from within a file?
If not, is there any equivalent way to pass the (gdb) info breakpoints output to a file or a program while pipe is not available in GDB (version 5.3)? Currently I'm trying a workaround by using logging feature for that purpose:
set logging file /tmp/breakpoints
set logging on
info breakpoints
set logging off
Is there any easy way to set some predetermined commands for a predetermined breakpoint from within a file?
Yes: if you use commands without NUM, the commands will apply to the last breakpoint set. So you want something like:
break main.c:18
commands
silent
print buffer[0]
cont
end

Is there a "watch window" like GDB function?

In gdb, when it hits a breakpoint, I need to manually investigate the variable values, one by one, with print or print/x functions.
Is there any easier way to list all selected variable's values whenever it hits a breakpoint, commonly known as a "watch window" of a GUI debugger?
Commands can be executed on breakpoints.
From docs:
break foo
commands
printf "x is %d\n",x
end
Or add commands to some existing breakpoint (breakpoint number 3 in this case):
commands 3
print x
print y
end
Or make a command that adds prints to a breakpoint:
define addwatch
commands $arg0
print x
print y
end
end
Then use:
addwatch 3
Or make a command that sets a breakpoint and adds prints to it.
Scripts can be stored in .gdbinit, so they'll load automatically. The language is either this GDB syntax or Python.
P.S. Some people do tracing with this by adding continue at the end of the command list: that way the variables are printed, but the application doesn't stop on the breakpoint.

Calling external script on breakpoint with Register Values as parameters

I would like to script Trace32 so I can dump register state and pass to my script on a breakpoint trigger.
I am currently looking at the /CMD flag.
Is there any way I can set a breakpoint in the format of this:
Break.set main /CMD "OS.Command MyScript.sh $R0 $R1 $R2 ..."
where I am dumping the registers and passing it to MyScript as parameters.
My backup plan is to use wp.Register and have my script monitor file system instead.
Thanks ahead for help!
I have this solution.
When setting the breakpoint, instead use /CMD "DO bkpt_trigger.cmm"
Then in bkpt_trigger.cmm
&r0=Register(R0)
&r1=Register(R1)
...
Os.Command echo &r0 &r1

Lauterbach execute script when breakpoint is hit

I am using Lauterbach to debug a PowerPC embedded C software. I want to execute the below ALGO from a .cmm(PRACTICE) script. Pleas let me know if it is possible:
Set Breakpoint
When Breakpoint is hit, execute a .cmm file. This .cmm file will rewrite the values of an array.
Continue execution of program
I don't want to stub the whole function. The code has to be untouched.
Set the breakpoint with
Break.Set <addr> /Program /CMD "DO myScript.cmm"
To continue the execution of the target program, add the command Go to the end of the called PRACTICE script.
If you can't add the command Go to the end of the called PRACTICE script, you'll need a veneer-script like this:
// Content of myScript.cmm
DO myAlgorithm.cmm
Go
ENDDO
The Break.Set command knows also an option /RESUME, but this is not suitable for your case, since it won't wait until the called PRACTICE script has finished.
As you have mentioned !
I don't want to stub the whole function. The code has to be untouched.
You can try this;
;set a breakpoint on function
BREAK.SET <function_name/addr>\<LINE NUMBER>
;store address of current program counter(PC)
&pc=r(pc)
&call=address.offset(<function_name/addr>\<LINE NUMBER>) ;This will give the address of a function where breakpoint is set.
;Compare the address if it hit on correct function
IF (&pc==&call)
Do call_meonceHIT.cmm ;your desired .cmm script.
Break.Delete /ALL ; to delete all the set breakpoint.
This will make sure that breakpoint is hitting correct function or runnable.

Is there a way to reset breakpoint stats in GDB?

Assume the following .gdbinit:
break foobar
ignore 1 1
run
The program is started using gdb --args ./myprogram --argument1 --argument2 etc.
Now, when I start this the first time around all is fine and dandy. However, if I issue a run on the (gdb) prompt in order to restart the program with the last-known command line, the ignore line will simply not take effect.
The reason is of course clear. The first time around I end up with
(gdb) info break
Num Type Disp Enb Address What
1 breakpoint keep y 0x000000000061ea6a in foobar at ../foobar.c:1173
breakpoint already hit 1 time
And any subsequent run starts with whatever value is shown for X in breakpoint already hit X time. Naturally that value will already exceed the limit set by ignore.
How can I reset the stats on the breakpoints or better yet how can I cause run to do that automatically for me?
How can I reset the stats on the breakpoints or better yet how can I cause run to do that automatically for me?
One way to do that is:
# ~/.gdbinit
break foobar
break main
commands 2
silent
ignore 1 1
continue
end
Now, every time you run, you hit silent breakpoint on main, which resets the ignore count on foobar breakpoint and continues.