| |

VerySource

 Forgot password?
 Register
Search
View: 3499|Reply: 27

Function call stack view

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-9 08:40:01
| Show all posts |Read mode
How to see which function is called at runtime?
Reply

Use magic Report

0

Threads

14

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 Hong Kong

Post time: 2020-1-9 20:18:01
| Show all posts
debugging
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-19 20:54:02
| Show all posts
Added: Not in the state of debugging,

That is, which function is called by the API
Reply

Use magic Report

0

Threads

14

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 Thailand

Post time: 2020-1-20 10:36:02
| Show all posts
There doesn't seem to be such a function in the api. In fact, you can add such a function to each function as needed, including in which window the information is output.
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-4-18 01:30:01
| Show all posts
Seems to be in vc ++. . I do n’t know the specific
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-4-20 09:45:01
| Show all posts
General debugging tools with an interface have a call stack function to see the call stack
Reply

Use magic Report

1

Threads

13

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-20 10:00:01
| Show all posts
Selecting a caller in source sight seems ...
Reply

Use magic Report

0

Threads

15

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-4-28 15:15:01
| Show all posts
There is a dumb way

Manually write the called information to the file when calling
Reply

Use magic Report

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-29 08:15:01
| Show all posts
The DEBUG version is simpler, get the function stack frame through ebp, you can get the call stack ...
The RELEASE version does not work, because many functions are not compiled and optimized to generate stack frames, some boring guys will use ebp to do boring things, the difficulty is high ...
Reply

Use magic Report

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-5-6 22:00:01
| Show all posts
Boring .....

#include <stdio.h>
#include <stdlib.h>

int cc = 0;
static void entry ();
static void foo1 ();
static void foo2 ();
static void foo3 ();
static void foo4 ();
static void traceCallStack ();

#define FOOBAR (__name__)\
void __name __ () {\
if (++ cc> = 100)\
{if (cc% 16 == 0) traceCallStack ();}\
else switch (rand ()% 4) {\
case 0: foo1 (); foo2 (); break;\
case 1: foo2 (); foo3 (); break;\
case 2: foo3 (); foo4 (); break;\
case 3: if (! (rand ()% 4)) traceCallStack (); break;\
}}

FOOBAR (foo1);
FOOBAR (foo2);
FOOBAR (foo3);
FOOBAR (foo4);

struct name_rcd_st {
void * func;
const char * name;
int brk;}
name_rcd [] =
{
{entry, "entry", 1},
{foo1, "foo1"},
{foo2, "foo2"},
{foo3, "foo3"},
{foo4, "foo4"},
{traceCallStack, "traceCallStack"},
{NULL, NULL}
};

int name_rcd_compare (const void * lhs, const void * rhs)
{
return (int) ((struct name_rcd_st *) rhs)-> func-(int) ((struct name_rcd_st *) lhs)-> func;
}

void entry ()
{
foo1 ();
}

int main ()
{
qsort (name_rcd, sizeof (name_rcd) / sizeof (name_rcd [0])-1, sizeof (name_rcd [0]), name_rcd_compare);
entry ();
return 0;
}

/ *
 ----------------------- <-EBP
      OLD EBP
 -----------------------
      RET ADDR
 -----------------------
 * /

#define CURR_FRAME (r) __asm ​​mov r, ebp
#define NEXT_FRAME (c, r) r = ((void **) c) [0]
#define RET_ADDR (c, r) r = ((void **) c) [1]

void * getFrame (void * curr_frame, void ** next_frame_ret)
{
void * next_frame, * ret_addr;
if (NULL == curr_frame)
{
CURR_FRAME (curr_frame);
}
NEXT_FRAME (curr_frame, next_frame);
RET_ADDR (curr_frame, ret_addr);
* next_frame_ret = next_frame;
return ret_addr;
}

struct name_rcd_st * find_func (void * addr, int * off)
{
struct name_rcd_st * r = name_rcd;

for (; r-> func; ++ r)
{
if (addr> r-> func)
break;
}

if (! r-> func)
return NULL;

* off = (int) addr-(int) r-> func;
return r;
}

void traceCallStack ()
{
struct name_rcd_st * rcd;
void * curr_frame = NULL, * addr_func;
int brk = 0, off = 0;

printf ("\n ..... traceCallStack begin:\n");

while (! brk)
{
addr_func = getFrame (curr_frame,&curr_frame);
rcd = find_func (addr_func,&off);
if (! rcd) break;
brk = rcd-> brk;
printf ("% s +% d\n", rcd-> name, off);
}

printf ("........ traceCallStack end ....\n");
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list