stackframe

Static global variables vs global variables C

孤者浪人 提交于 2019-12-11 10:36:12
问题 I have the program below. If i declare variables a,b,c static global variables, it gives segmentation fault, but if i declare them non-static global or as local variables, it won't give segmentation fault. Why does it behave in such a way? I know that there is more data than variables can store, but why does it give seg fault when only its declared static? Are statically declared variables stored in some different part of the the stack frame where overwriting is not allowed? EDIT: I know

Does -fomit-frame-pointer *always* omit the fp?

社会主义新天地 提交于 2019-12-11 00:47:50
问题 Does -fomit-frame-pointer always omit the frame pointer? Is there ever a situation where both the pc and fp need to be setup? Does dynamic stack growth force the fp to be setup? Asking specifically for MIPS32. Thanks! 回答1: The frame pointer is not really needed for correct execution, except sometimes for exception unwind. Dynamic stack growth usually requires some kind of a frame pointer, but it is not tied to a particular register, but rather allocated through normal data flow analysis.

Evaluating if a stack overflow error is possible in a tree traversal recursive algorithm (Java)

送分小仙女□ 提交于 2019-12-10 17:13:31
问题 What is the best way to determine theoretically (i.e., without actually executing it) the circumstances in which a certain tree traversal recursive algorithm will produce a stack overflow in Java? In order to clarify my question, consider the following example. Given a simple binary tree implemented in Java: public class Node { private int value; private Node left; private Node right; ... //in-order traversal public void inOrder() { if (left != null) { left.inOrder(); } System.out.println

Portable function in C (with no assembly) that returns the size of its stack frame

江枫思渺然 提交于 2019-12-10 16:33:31
问题 Write a portable function in C (with no assembly) that returns the size of its stack frame int stackframe_size() { } Attempted solving it as below - This function returns 228 bytes when compiled with VS 2010. Is there a way to verify its correctness? int stackframe_size(int run) { int i ; if(!run) { return ((int)(&i) - stackframe_size(++run)); } return (int)(&i); } Invoked as: int main() { printf("\nSize of stackframe_size() is: %d bytes",stackframe_size(0)) ; return 0; } 回答1: No such

Ebp, esp and stack frame in assembly with nasm

放肆的年华 提交于 2019-12-09 03:16:58
问题 I have a few questions about ebp, esp and stack frame in following code. Why did we substract 28 from esp ? We have two local variables x and y in main. So why didn't we substract 8? And don't we put values to stack from right to left? So why did we add 1 to [eax+8] instead of [eax+4] ? I am a little bit confuse about this structure. Can you help me out? Thx. func(int a, int b, int c) { return a+b+c; } main() { int x, y=3; x=func(y,2,1); } 回答1: The stack pointer is subtracted by 28 because

Obtaining references to function objects on the execution stack from the frame object?

徘徊边缘 提交于 2019-12-08 23:02:31
Given the output of inspect.stack() , is it possible to get the function objects from anywhere from the stack frame and call these? If so, how? (I already know how to get the names of the functions.) Here is what I'm getting at: Let's say I'm a function and I'm trying to determine if my caller is a generator or a regular function? I need to call inspect.isgeneratorfunction() on the function object. And how do you figure out who called you? inspect.stack() , right? So if I can somehow put those together, I'll have the answer to my question. Perhaps there is an easier way to do this? Here is a

How to check if a variable with a given name is nonlocal?

ぐ巨炮叔叔 提交于 2019-12-08 02:56:08
问题 Given a stack frame and a variable name, how do I tell if that variable is nonlocal? Example: import inspect def is_nonlocal(frame, varname): # How do I implement this? return varname not in frame.f_locals # This does NOT work def f(): x = 1 def g(): nonlocal x x += 1 assert is_nonlocal(inspect.currentframe(), 'x') g() assert not is_nonlocal(inspect.currentframe(), 'x') f() 回答1: Check the frame's code object's co_freevars , which is a tuple of the names of closure variables the code object

What does EBP+8 in this case in OllyDbg and Assembler mean?

喜欢而已 提交于 2019-12-07 05:14:58
问题 I am just learning Assembler and debugging skills in OllyDbg in order to learn how to use undocumented functions. Now I am having the following problem: I have the following code part (from OllyDbg): MOV EDI,EDI PUSH EBP MOV EBP,ESP MOV EAX, DWORD PTR SS:[EBP+8] XOR EDX,EDX LEA ECX, DWORD PTR DS:[EAX+4] MOV DWORD PTR DS:[EAX], EDX MOV DWORD PTR DS:[ECX+4],ECX MOV DWORD PTR DS:[ECX],ECX MOV DWORD PTR DS:[EAX+C],ECX MOV ECX, DWORD PTR SS:[EBP+C] This is the beginning of the function and the

How to check if a variable with a given name is nonlocal?

自作多情 提交于 2019-12-06 13:32:30
Given a stack frame and a variable name, how do I tell if that variable is nonlocal? Example: import inspect def is_nonlocal(frame, varname): # How do I implement this? return varname not in frame.f_locals # This does NOT work def f(): x = 1 def g(): nonlocal x x += 1 assert is_nonlocal(inspect.currentframe(), 'x') g() assert not is_nonlocal(inspect.currentframe(), 'x') f() Check the frame's code object's co_freevars , which is a tuple of the names of closure variables the code object uses: def is_nonlocal(frame, varname): return varname in frame.f_code.co_freevars Note that this is

How does Smalltalk manipulate call stack frames (thisContext)?

故事扮演 提交于 2019-12-06 03:38:57
问题 The Smalltalk object thisContext look strange and marvelous. I can't understand what it is and how it works. And even how it enables continuations. For C's call-stack, I can easily imagine how is it implemented and working. But for this... I can't. Please help me to understand it. 回答1: I think it is not an easy question. The stack is reified in the image with instances of MethodContext. A MethodContext can have a sender, which is another MethodContext. That one can have another one..