?
Solved

How can I get the suspended thread context?

Posted on 2003-03-27
6
Medium Priority
?
336 Views
Last Modified: 2010-04-21
Hi,

I want to suspend a thread and then get the conext of the thread after it is suspended.
I add a signal handler. But the handler does not run in the thread context.

How can I do it? Thanks.
0
Comment
Question by:hackbuteer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 8234849
please post code
0
 

Author Comment

by:hackbuteer
ID: 8250734
This is my test code.
Now I am sure I can get the stack top of the thread in the signal handler. But I want to get the more precise information about the thread context, like ESP, EIP, EBP of the last frame of the thread.

How can I do it?

Thank you very much.

==============================

pthread_attr_t pthread_attr;

void (*original_handler)(int) = NULL;
int mm = 0;

void signal_handler(int sig)
{
   int y;
   printf("y address is %#x\n", (int)&y);
}
 
void * thread_run(void* param )
{
    int x;
    printf("x address is %#x\n", (int)&x);
    original_handler = signal( SIGUSR1, signal_handler);
        if( original_handler == SIG_ERR )
            printf("signal() failed\n");
    mm = 1;
     
    while( mm != 2 )
        sleep(1);

    return 0;
}

int attach_system_thread(void)
{
  int stat;
  pthread_t tid = 0;
  void *(*sa)(void *) = ( void *(*)(void *) )thread_run;

  stat = pthread_create(&tid, 0, sa, 0);
  printf("tid=%#x\n", tid);
  assert(stat == 0);
   
  return (int)tid;

}

int main(void)
{
    int tid = attach_system_thread();
    while( mm != 1 )
        sleep(10);

    if( pthread_kill(tid, SIGUSR1) == -1 )
    {
        printf(" send signal failed %#x( EINVAL=%#x, ESRCH=%#x, EPERM=%#x )\n", errno, EINVAL, ESRCH, EPERM);
    }else{
        int i;
        for( i=0; i<4; i++ )
            sleep(1);
    }

    mm = 2;
     
    return 0;
}
0
 

Expert Comment

by:slironm
ID: 8278270
Why not do the opposite - first catch the signal, see the state, and only then suspend the thread?

Liron.
0
Stressed Out?

Watch some penguins on the livecam!

 

Author Comment

by:hackbuteer
ID: 8282232
Yes, I want to do that.
I suspend the thread in the signal handler, I can get the return address. But where can I get the stored EIP?
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10225181
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 10286647
PAQed, with points refunded (250)

Computer101
E-E Admin
0

Featured Post

Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question