callstack

How to get the name of the calling class in Java?

只谈情不闲聊 提交于 2019-11-26 14:44:28
I would like some help on this matter, Example: public class A { private void foo() { //Who Invoked me } } public class B extends A { } public class C extends A { } public class D { C.foo(); } This is basically the scenario. My question is how can method foo() know who is calling it? EDIT : Basically I am trying to do a database Layer, and in Class A I will create a method that will generate SQL statements. Such statements are dynamically generated by getting the values of all the public properties of the calling class. Easiest way is the following: String className = new Exception()

What causes a java.lang.StackOverflowError

佐手、 提交于 2019-11-26 14:28:10
What can cause a java.lang.StackOverflowError ? The stack printout that I get is not very deep at all (only 5 methods). Check for any recusive calls for methods. Mainly it is caused when there is recursive call for a method. A simple example is public static void main(String... args) { Main main = new Main(); main.testMethod(1); } public void testMethod(int i) { testMethod(i); System.out.println(i); } Here the System.out.println(i); will be repeatedly pushed to stack when the testMethod is called. One of the (optional) arguments to the JVM is the stack size. It's -Xss. I don't know what the

Does java have any mechanism for a VM to trace method calls on itself, without using javaagent, etc?

家住魔仙堡 提交于 2019-11-26 12:24:22
问题 I want to build call graphs on the fly, starting at an arbitrary method call or with a new thread, which ever is easier, from within the running JVM itself. (this piece of software is going to be a test fixture for load testing another piece of software that consumes call graphs) I understand there are some SPI interfaces, but it looks like you need to run -javaagent flag with them. I want to access this directly in the VM itself. Ideally, I\'d like to get a callback for entry and exit of

Why does the stack address grow towards decreasing memory addresses?

夙愿已清 提交于 2019-11-26 12:11:13
问题 I read in text books that the stack grows by decreasing memory address; that is, from higher address to lower address. It may be a bad question, but I didn\'t get the concept right. Can you explain? 回答1: First, it's platform dependent. In some architectures, stack is allocated from the bottom of the address space and grows upwards. Assuming an architecture like x86 that stack grown downwards from the top of address space, the idea is pretty simple: =============== Highest Address (e.g. 0xFFFF

How do I print functions as they are called

僤鯓⒐⒋嵵緔 提交于 2019-11-26 11:50:39
问题 In debugging a Python script, I\'d really like to know the entire call stack for my entire program. An ideal situation would be if there were a command-line flag for python that would cause Python to print all function names as they are called (I checked man Python2.7 , but didn\'t find anything of this sort). Because of the number of functions in this script, I\'d prefer not to add a print statement to the beginning of each function and/or class, if possible. An intermediate solution would

Array to pointer decay and passing multidimensional arrays to functions

[亡魂溺海] 提交于 2019-11-26 11:45:59
I know that an array decays to a pointer, such that if one declared char things[8]; and then later on used things somewhere else, things is a pointer to the first element in the array. Also, from my understanding, if one declares char moreThings[8][8]; then moreThings is not of type pointer to char but of type "array of pointers to char," because the decay only occurs once. When moreThings is passed to a function (say with prototype void doThings(char thingsGoHere[8][8]) what is actually going on with the stack? If moreThings is not of pointer type, then is this really still a pass-by

Debugging VBA, Locating Problems, and Troubleshooting Methods [closed]

浪子不回头ぞ 提交于 2019-11-26 11:27:58
问题 What are some methods of debugging VBA code ? Specifically: Stepping through code Breakpoints and the Stop command The Debug command Locals & watch windows Call stack 回答1: Debugging VBA Code This page describes methods for debugging your VBA code. Introduction Debugging a program is one of the most important steps in software development. Knowledge of VBA's debugging tools can make debugging easier and more productive. This page describes several of VBA's built-in debugging tools you can use

Why does gcc use movl instead of push to pass function args?

若如初见. 提交于 2019-11-26 11:26:31
问题 pay attention to this code : #include <stdio.h> void a(int a, int b, int c) { char buffer1[5]; char buffer2[10]; } int main() { a(1,2,3); } after that : gcc -S a.c that command shows our source code in assembly. now we can see in the main function, we never use \"push\" command to push the arguments of the a function into the stack. and it used \"movel\" instead of that main: pushl %ebp movl %esp, %ebp andl $-16, %esp subl $16, %esp movl $3, 8(%esp) movl $2, 4(%esp) movl $1, (%esp) call a

Is there any way to set a breakpoint in gdb that is conditional on the call stack?

浪子不回头ぞ 提交于 2019-11-26 08:27:20
问题 I am debugging C++ in gdb 7.1 on Linux. I have a function a() that is called in many places in the code. I want to set a breakpoint in it, but only if it was called from b() . Is there any way to do it? Is there any way to do it only if b() was called from c() , and so on ad infinitum? 回答1: Update: There is now a better answer to this question: use GDB _is_caller convenience function. The need you describe comes up quite often, usually in the context of some_utility_fn being called a lot, but

What causes a java.lang.StackOverflowError

丶灬走出姿态 提交于 2019-11-26 05:56:10
问题 What can cause a java.lang.StackOverflowError ? The stack printout that I get is not very deep at all (only 5 methods). 回答1: Check for any recusive calls for methods. Mainly it is caused when there is recursive call for a method. A simple example is public static void main(String... args) { Main main = new Main(); main.testMethod(1); } public void testMethod(int i) { testMethod(i); System.out.println(i); } Here the System.out.println(i); will be repeatedly pushed to stack when the testMethod