标签: callstack

如何在Perl中检测递归包调用?

我有一个Perl项目,我通过打一个循环包调用问题.下面的代码演示了这个问题.

执行此操作时,每个程序包将调用另一个程序包,直到计算机的所有内存都被占用并锁定.我同意这是一个糟糕的设计,这样的循环调用不应该在设计中进行,但我的项目足够大,我想在运行时检测到这一点.

我已经阅读了弱化函数和Data :: Structure :: Util,但我还没有找到一种方法来检测是否存在循环包加载(我假设,因为在每次迭代时都会生成一个新副本并存储在$ this hash的每个副本中).有任何想法吗?

use system::one;

my $one = new system::one(); 

package system::one;

use strict;

use system::two;

sub new {
  my ($class) = @_; 
  my $this = {};  
  bless($this,$class); 
  # attributes
  $this->{two} = new system::two();
  return $this; 
} 

package system::two;

use strict;

use system::one;

sub new {
  my ($class) = @_; 
  my $this = {};  
  bless($this,$class); 
  # attributes
  $this->{one} = new system::one();
  return $this; 
} 
Run Code Online (Sandbox Code Playgroud)

recursion perl callstack packages object

6
推荐指数
1
解决办法
1014
查看次数

有没有办法知道调用方法?

我知道类方法告诉对象类的名称是什么,我怎么知道调用方法的名称?有没有办法知道这个?

ruby callstack

6
推荐指数
1
解决办法
262
查看次数

比Stackwalk更快

有没有人知道更好/更快的方式获得调用堆栈比"StackWalk"?我也认为对于有很多变量的方法,stackwalk也可能会变慢...(我想知道商业分析器的用途是什么?)我在Windows上使用C++.:) 谢谢 :)

c++ windows callstack

6
推荐指数
1
解决办法
3008
查看次数

堆栈调试已调试的进程

我打开了一个进程(使用C++/Windows)

if( CreateProcessA( NULL,   // No module name (use command line)
   (LPSTR)path, //argv[1],        // Command line
    NULL,           // Process handle not inheritable
    NULL,           // Thread handle not inheritable
    FALSE,          // Set handle inheritance to FALSE
    creationFlags,              // No creation flags
    NULL,           // Use parent's environment block
    NULL,           // Use parent's starting directory 
    &startInfo,            // Pointer to STARTUPINFO structure
    &processInfo )           // Pointer to PROCESS_INFORMATION structure
Run Code Online (Sandbox Code Playgroud)

哪里

DWORD creationFlags = DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS;  
Run Code Online (Sandbox Code Playgroud)

然后我试着用它来堆积它

bool ok = StackWalk64(IMAGE_FILE_MACHINE_I386,m_ps.Handle ,m_th.Handle, 
    &m_stackframe, &m_threadContext, …
Run Code Online (Sandbox Code Playgroud)

c++ windows debugging callstack

6
推荐指数
1
解决办法
861
查看次数

检索方法或构造函数的调用者实例(而不是类)

是否可以检索方法/构造函数的调用者实例?

这个问题已经发布,但每次答案都是关于调用者类(使用堆栈跟踪)而不是调用者实例.如果存在解决方案,那么构建对象图(具有公共超类型)并使用默认构造函数处理父子导航可能非常方便.

public class TestCallStack {
    public static class BaseClass {
        BaseClass owner;
//      //ok, this is the correct way to do it
//      public BaseClass(BaseClass owner) {
//          this.owner = owner;
//      }
        public BaseClass() {
            //this.owner = ???????; 
        }
    }
    public static class Parent extends BaseClass {
        Child child = new Child();
    }
    public static class Child extends BaseClass {
    }

    public static void main(String[] args) {
        Parent parent = new Parent();
        System.out.println(parent.child.owner==parent); // must be true
    } …
Run Code Online (Sandbox Code Playgroud)

java inheritance callstack stack-trace

6
推荐指数
1
解决办法
2620
查看次数

R:承诺已经在评估中

我知道您可能已经厌倦了再次回答相同的问题,但我仍然在其他几个 问题中讨论了错误:

承诺已经在评估中:递归默认参数引用还是早期问题?

即使我确实遵循了前期的"繁琐"建议".":

show.large.objects.threshold <- 100000
show.large.objects.exclude <- c("closure")
show.large.objects <- function (.envir = sys.frame(),
                                threshold = show.large.objects.threshold,
                                exclude = show.large.objects.exclude) {
  for (n in print(ls(.envir, all.names = TRUE))) tryCatch({
    o <- get(n,envir = .envir)
    s <- object.size(o)
    if (s > threshold && !(typeof(o) %in% exclude)) {
      cat(n,": ")
      print(s,units="auto")
    }
  }, error = function(e) { cat("n=",n,"\n"); print(e) })
}
show.large.objects.stack <- function (.threshold = show.large.objects.threshold,
                                      skip.levels = 1,# do not examine the last …
Run Code Online (Sandbox Code Playgroud)

callstack r lazy-evaluation

6
推荐指数
1
解决办法
2839
查看次数

CasperJs then()是否等待上一个函数中发出的事件?

我很好奇CasperJS如何处理与调用堆栈有关的事件.

假设我们有一些代码:

casper.on('foo', function() {
    this.wait(60000);
    this.echo('foo');
});


casper.start('http://www.stackoverflow.com', function() {
    this.echo('start');
    this.emit('foo');
});


casper.then(function() {
    this.echo('done');
});

casper.run();
Run Code Online (Sandbox Code Playgroud)

我知道then()将等待检查3个标志:pendingWait,loadInProgress和navigationRequested.打印出调用堆栈会将emit调用显示在函数start()中,因此在事件结束之前start()不会被视为已完成?即,然后()等待事件结束

我等了60秒测试了这个,我确实得到了输出:

start
foo
done
Run Code Online (Sandbox Code Playgroud)

虽然我不确定超过某个超时是否会触发下一个().

javascript events callstack casperjs

6
推荐指数
1
解决办法
1453
查看次数

产生深度调用堆栈的代码是否被视为反模式?

我们正在围绕LLVM库进行研究,我们发现IR库有时会达到最多29个方法调用的调用堆栈.

有时当我在iOS框架中看到一些崩溃时,我也会观察到相当深的调用堆栈.

我的问题是,我们是否可以推断一个代码的设计是否存在问题,而这个代码的设计自称是如此之大.

这是一个例子:

/usr/local/LLVM/llvm/unittests/IR/AttributesTest.cpp:54
  /usr/local/LLVM/llvm/lib/IR/LLVMContext.cpp:162
    /usr/local/LLVM/llvm/lib/IR/LLVMContext.cpp:162
      /usr/local/LLVM/llvm/lib/IR/LLVMContextImpl.cpp:54
        /usr/local/LLVM/llvm/lib/IR/LLVMContextImpl.cpp:59
          /usr/local/LLVM/llvm/lib/IR/Module.cpp:60
            /usr/local/LLVM/llvm/lib/IR/Module.cpp:62
              /usr/local/LLVM/llvm/lib/IR/Module.cpp:456
                /usr/local/LLVM/llvm/lib/IR/Function.cpp:350
                  /usr/local/LLVM/llvm/lib/IR/BasicBlock.cpp:98
                    /usr/local/LLVM/llvm/include/llvm/ADT/ilist.h:282
                      /usr/local/LLVM/llvm/include/llvm/ADT/ilist.h:267
                        /usr/local/LLVM/llvm/lib/IR/SymbolTableListTraitsImpl.h:76
                          /usr/local/LLVM/llvm/lib/IR/BasicBlock.cpp:90
                            /usr/local/LLVM/llvm/lib/IR/SymbolTableListTraitsImpl.h:58
                              /usr/local/LLVM/llvm/lib/IR/ValueSymbolTable.cpp:75
                                /usr/local/LLVM/llvm/lib/IR/ValueSymbolTable.cpp:47
                                  /usr/local/LLVM/llvm/include/llvm/Support/Casting.h:132
                                    /usr/local/LLVM/llvm/include/llvm/Support/Casting.h:112
                                      /usr/local/LLVM/llvm/include/llvm/Support/Casting.h:122
                                        /usr/local/LLVM/llvm/include/llvm/Support/Casting.h:96
                                          /usr/local/LLVM/llvm/include/llvm/IR/Value.h:777
                                            /usr/local/LLVM/llvm/include/llvm/Support/Casting.h:132
                                              /usr/local/LLVM/llvm/include/llvm/Support/Casting.h:122
                                                /usr/local/LLVM/llvm/include/llvm/Support/Casting.h:75
                                                  /usr/local/LLVM/llvm/include/llvm/IR/Value.h:771
                                                    /usr/local/LLVM/llvm/include/llvm/Support/Casting.h:132
                                                      /usr/local/LLVM/llvm/include/llvm/Support/Casting.h:122
                                                        /usr/local/LLVM/llvm/include/llvm/Support/Casting.h:75
                                                          /usr/local/LLVM/llvm/include/llvm/IR/Value.h:759
Run Code Online (Sandbox Code Playgroud)

PS示例调用堆栈实际上是由LLVMContext类的析构函数生成的:LLVMContext::~LLVMContext().这是来自Java世界的一篇非常古老的帖子的另一个例子:Java调用栈 - 从HTTP到JDBC作为图片.

callstack anti-patterns llvm

6
推荐指数
1
解决办法
563
查看次数

x86程序集:弹出一个值而不存储它

在x86程序集中,是否可以从堆栈中删除值而不存储它?有什么东西沿着pop word null?我显然可以使用add esp,4,但也许有一个很好的和干净的cisc助记符我不见了?

x86 assembly stack callstack stack-pointer

6
推荐指数
1
解决办法
1406
查看次数

为什么要提供“ HasCallStack”机制,因为我们在GHC中已经有“ ghc -prof -fprof-auto-top”?

AFAIK,有两种方法可以获取调用堆栈以在Haskell中进行调试:

  1. HasCallStack在代码中添加约束
  2. 用编译代码 ghc -prof -fprof-auto-top

我的测试代码:

import GHC.Stack

-- | a wrapper function to make "last" from base traceable
last' :: HasCallStack => [a] -> a
last' xs = case xs of [] -> error "abuse last"; _ -> last xs

-- | a untraceable partial function
foo :: [Int] -> Int
foo xs = last' xs + 1

-- | a untraceable partial function
-- , which looks like traceable, but it's call stack is cut off …
Run Code Online (Sandbox Code Playgroud)

callstack haskell ghc

6
推荐指数
1
解决办法
94
查看次数