Regarding stack analysis


 
Thread Tools Search this Thread
Top Forums Programming Regarding stack analysis
# 1  
Old 06-22-2008
Regarding stack analysis

I would like to know how I could do the following :

Code:
void func(){
  int a = 100; b=0;
  int c = a/b;
}

void sig_handler (int sig,siginfo_t *info,void *context){
//signal handling function
//here I want to access the variables of func() 
}
  
int main(){
  struct sigaction *act = (struct sigaction *)malloc(sizeof(struct sigaction));
  act->sa_flags = SA_SIGINFO;
  act->sa_sigaction = sig_handler; 
  sigaction(SIGFPE,act,NULL); 
  func();
}

As expected, this program should give an exception. But I use sigaction to catch the signal (arithmetric exception) and send control to another function(sig_handler), where I want to handle this signal.

I would like to access the variables inside func() and modify them. How can I do this ?

thank you,

Last edited by vpraveen84; 06-22-2008 at 10:54 PM..
# 2  
Old 06-23-2008
Normally, coders test for division by zero in the function and take corrective action to the values before SIGFPE hits the process. Not after.

With your method, you will need global pointers to the problem value(s), but how do you expect to correct the problem? You have already gone past the division step. Call the function again from the signal handler? Then what happens? The code sets b=0 again and you get another SIGFPE, and you are back where you started.
# 3  
Old 06-23-2008
Quote:
Originally Posted by jim mcnamara
Normally, coders test for division by zero in the function and take corrective action to the values before SIGFPE hits the process. Not after.

With your method, you will need global pointers to the problem value(s), but how do you expect to correct the problem? You have already gone past the division step. Call the function again from the signal handler? Then what happens? The code sets b=0 again and you get another SIGFPE, and you are back where you started.
I understand what you are saying, but my aim is not exception handling. I want to modify certain memory locations before dumping the core , and this is why I want access to the local variables in func().

For instance, we've the ucontext_t (in sigaction) which gives the context of the exception(similar to setjmp env). But I don't know how I can get a mapping between the variables in func() and the context ?

thanks.

Last edited by vpraveen84; 06-23-2008 at 02:26 PM..
# 4  
Old 06-23-2008
If you want to modify function-local variables via some form of stack inspection/modification in an attempt to add global exception handling in C I'd respectfully suggest you are doing it wrong.

C based interpreted languages have these kinds of features without breaking C. Maybe you don't really want C at all.

Also gdb has all these introspection capabilities. Learn the debugger.

Last edited by ramen_noodle; 06-23-2008 at 06:01 PM..
# 5  
Old 06-23-2008
Bug Go Global

Either make those global variables or use the setjmp() and longjmp() calls. Caveat with setjmp() and longjmp() is that only one of the local variables of main() either a, b, or c can be changed by func() not all of them. To change all of them declare them as globals.
# 6  
Old 06-24-2008
I think he wants to the core to be created, and I'm guessing there is a security problem with having the core file sitting out there. ulimit can turn off core creation.
# 7  
Old 06-26-2008
Question Requirements unclear

The OP needs to clarify what exactly is needed.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Infrastructure Monitoring

Nmon Analysis

Dear All, I am an performance tester. Now i am working in project where we are using linux 2.6.32. Now I got an oppurtunity to learn the monitoring the server. As part of this task i need to do analysis of the Nmon report. I was completely blank in this. So please suggest me how to start... (0 Replies)
Discussion started by: iamsengu
0 Replies

2. UNIX for Dummies Questions & Answers

Kernel Stack vs User Mode Stack

Hi, I am new to the linux kernel development area. I want to know what is the difference between kernel mode stack and user mode stack? Does each process has a user mode stack and a kernel mode stack?? Or Each process has a user mode stack and there is only one kernel mode stack that is shared by... (4 Replies)
Discussion started by: saurabhkoar
4 Replies

3. UNIX for Dummies Questions & Answers

Text analysis

Hey Guys, Does anyone know how to count the separate amount of words in a text file? e.g the 5 and 20 Furthermore does anyone know how to convert whole numbers in decimals? Thanks (24 Replies)
Discussion started by: John0101
24 Replies

4. Shell Programming and Scripting

Metacharacters analysis

:confused:Hi , Can someone please advise what is the meaning of metacharacters in below code? a_PROCESS=${0##*/} a_DPFX=${a_PROCESS%.*} a_LPFX="a_DPFX : $$ : " a_UPFX="Usage: $a_PROCESS" Regards, gehlnar (3 Replies)
Discussion started by: gehlnar
3 Replies

5. Programming

what is stack winding and stack unwinding

helo can u tell me what do you mean by stack winding and stack unwinding Regards, Amit (2 Replies)
Discussion started by: amitpansuria
2 Replies

6. Solaris

Catalina Analysis

How can I make analysis for catalina.out (2 Replies)
Discussion started by: Burhan
2 Replies
Login or Register to Ask a Question