Trace32 doesn't wait until a command gets executed to execute the next command - trace32

I am running a Practice script inside Trace32. I have noticed that if for example I have this set of commands
Go
Step.Over
Step.Over doesn't necessarily wait for Go to finish execution to start. How to tell Trace32 not to execute a command until the other one finished. I have tried inserting Wait 2.s after each command. However, since I don't know how long the command will take that doesn't work in every run.

I assume that with "wait for Go to finish execution" you mean to wait until the processor hits a breakpoint. The Go command however does not wait until a breakpoint is reached. The execution of the Go command is completed as soon as the processor has been started.
Use the command WAIT <event> [<timeout>] to make the script wait for the breakpoint. The timeout is optional, but highly recommended for script robustness.
; start execution
Go
;wait until processor halts at breakpoint (timeout: 2 seconds)
WAIT !STATE.RUN() 2s
;error handler
IF STATE.RUN()
(
PRINT %ERROR "Breakpoint not reached!"
ENDDO
)
;continue stepping
Step.Over

Related

Process terminates with HUP signal despite starting with nohup

I'm quite new to solaris. I have this problem thats bugging me for sometime now.
I start a process in solaris as
nohup <binary>
I do this so that my process would not get SIGHUP, the process will not terminate even after I exit from my shell.
I tested this out, by exitting from my shell.
It works as expected,the process still runs.
Problem:
When my process is idle for too long, I see the following line in dmesg..
[ID 702911 auth.error] [29069] Run idle timeout reached (32400 seconds)
Then my process gets a SIGHUP, and terminates.
I'm struggling with the following questions...
Which process writes this timeout message in dmesg? How can I find it out?
How come my process still get a SIGHUP despite starting with nohup? Are there any other means for a process to get a HUP signal?
Note: I tried kill -1 <my process id> . Then my process terminates because of the HUP signal.
Can anyone help me on this?

Debugging multithread server in GDB- Find state of every thread. cont and stop while execution

I attached to my multithread application with gdb and after that type cont to continue execution.
Is there any way to stop execution at any time on cont gdb state and check what every thread do?
How to check state of every thread and get execution line number of each? (commands)
Here's what I do, (taken from here )
Create a little gdb script stackdumper.gdb that dumps the stack trace of all threads:
thread apply all backtrace
Then repeatedly attach gdb and run the dumper:
for i in $(seq 1 10) ; do
gdb -batch -x stackdumper.gdb ./a.out 123456 > stack.$i
sleep 10
done
where ./a.out is the binary you are interested and 123456 is the PID.
Adjust the sleep to match your sampling needs.
thread apply all bt
Or
info threads
t <threadid from above trace >
Followed by
where or bt
To get the backtrace for all of the stopped threads type the
thread apply all bt
command (the output is exactly the same that one might see in the MacOSX crash report box).
Usually the threads are stopped simultaneously in gdb.
Reference: http://www.delorie.com/gnu/docs/gdb/gdb_40.html
And here's about "all-stop" mode, which is default: http://sourceware.org/gdb/onlinedocs/gdb/All_002dStop-Mode.html
Is this any way to stop execution at any time on cont gdb state and check what every thread do
If you ask about ways to check what threads do without gdb the you can just run pstask <pid-of-your application>
Is it "pstack" because i don't think "pstask" is any command in linux, If it is please provide some more info

Debugging with GDB over several processes

Without getting into to to much detail, I'm working on a program that consists of several separate processes all running on embedded QNX RTOS. They don't have a parent-child relationship, they are all spawned using spawnlp(P_NOWAIT, ...) and they all communicate with each other using the IPC mechanism provided by the OS.
When I'm debugging with GDB and I hit a breakpoint in the process I'm working in, all of my threads are paused, which is great. But is there a way to also have it pause execution of my other processes? Right now what's happening is all the other processes keep on truckin' while my process is paused and so all the IPC queues get full etc. etc.
Thanks in advance,
HF
You can associate a list of GDB commands with each breakpoint. So when you hit a breakpoint in process A, you can for example send a SIGTRAP to process B, which should drop it into the debugger:
(gdb) b main
Breakpoint 1 at 0x804834a: file testA.c, line 40.
(gdb) command
Type commands for when breakpoint 1 is hit, one per line.
End with a line saying just "end".
>shell kill -s TRAP `pidof testB`
>end
(gdb)
More info at Breakpoint Command Lists

Executing new task based on sigchld() from previous task

I'm currently in the process of building a small shell within C++.
A user may enter a job at the prompt such as exe1 && exe2 &. Similar to the BASH shell, I will only execute exe2 if exe1 exits successfully. In addition, the entire job must be performed in the background (as specified by the trailing & operator).
Right now, I have a jobManager which handles execution of jobs and a job structure which contains the job's executable and their individual arguments / conditions. A job is started by calling fork() and then calling execvp() with the proper arguments. When a job ends, I have a signal handler for SIGCHLD, in which I perform wait() to determine which process has just ended. When exe1 ends, I observe its exit code and make a determination as to whether I should proceed to launch exe2.
My concern is how do I launch exe2. I am concerned that if I use my jobManager start function from the context of my SIGCHLD handler, I could end up with too many SIGCHLD handler functions hanging out on the stack (if there were 10 conditional executions, for instance). In addition, it just doesn't seem like a good idea to be starting the next execution from the signal handler, even if it is occurring indirectly. (I tried doing something similar 1.5 years ago when I was just learning about signal handling -- I seem to recall it failing on me).
All of the above needs to be able to occur in the background and I want to avoid having the jobManager sitting in a busy wait just waiting for exe1 to return. I would also prefer to not have a separate thread sitting around just waiting to start the execution of another process. However, instructing my jobManager to begin execution of the next process from the SIGCHLD handler seems like poor code.
Any feedback is appriciated.
I see two ways:
1)Replace you sighandler with loop that call "sigwait" (see man 3 sigwait)
then in loop
2)before start create pipe, and in mainloop of your program use "select" on pipe handle to wait
events. In signal handler write to pipe, and in mainloop handle situation.
Hmmm that's a good one.
What about forking twice, once per process? The first one runs, and the second one stops. In the parent SIGCHLD handler, send a SIGCONT to the second child, if appropriate, which then goes off and runs the job. Naturally, you SIGKILL the second one if the first one shouldn't run, which should be safe because you won't really have set anything up.
How does that sound? You'll have a process sitting around doing nothing, but it shouldn't be for very long.

Kill Bash copy child process to simulate crash

I'm trying to test a Bash script which copies files individually and does some stuff to each file. It is meant to be resumable, so I'd like to make sure to test this properly. What is an elegant solution to kill or otherwise abort the script which does the copying from the test script, making sure it does not have time to copy and process all the files?
I have the PID of the child process, I can change the source code of both scripts, and I can create arbitrarily large files to test on.
Clarification: I start the script in the background with &, get the PID as $!, then I have a loop which checks that there is at least one file in the target directory (the test script copies three files). At that point I run kill -9 $PID, but the process is not interrupted - The files are copied successfully. This happens even if the files are big enough that creating them (with dd and /dev/urandom) takes a couple seconds.
Could it be that the files are only visible to the shell when cp has finished? It would be a bit strange, but it would explain why the kill command is too late.
Also, the idea is not to test resuming the same process, but cutting off the first process (simulate a system crash) and resuming with another invocation.
Send a KILL signal to the child process:
kill -KILL $childpid
You can try an play the timing game by using large files and sleeps. You may have an issue with the repeatability of the test.
You can add throttling code to the script your testing and then just throttle it all the way down. You can do throttling code by passing in a value which is:
a sleep value for sleeping in the loop
the number of files to process
the number of seconds after which the script will die
a nice value to execute the script at
Some of these may work better or worse from a testing point of view. nice'ing may get you variable results, as will setting up a background process to kill your script after N seconds. You can also try more than one of these at the same time which may give you the control you want. For example, accepting both a sleep value and the kill seconds could give you fine grained throttling control.