[PATCH] D85458: Adding functionality to Stack Tracing

Dibya Ranjan Mishra via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 12:10:04 PDT 2020


dibya001 added inline comments.


================
Comment at: llvm/include/llvm/Support/PrettyStackTrace.h:99
+
+    void setArgs(int argC, const char *const *argV) {
+      this->ArgV = argV;
----------------
aganea wrote:
> dibya001 wrote:
> > aganea wrote:
> > > Please explain why this is needed. How would things work out in your code if neither `setArgs` nor the empty constructor were there?
> > I want to to declare PrettyStackTraceProgram's object globally so that I have access to it in other portions of code.  While declaring globally I don't have argc and argv, Hence I need this default constructor. And in main, I will call the setArgs with argc and argv values
> `PrettyStackTraceProgram` is just meant as a deferred instruction to the crash handler, telling it to print our custom stack of operations. It is not meant to be used explictly. The changes here seem specific to your use-case.
> How do you use in other parts of the code? I suppose you want `.print()`? I'm trying to understand what is your underlying need.
> 
> In your code, could you instead do:
> ```
> PrintStackTraceProgram *GlobalX{};
> int main(int argc, const char **argv) {
>   PrintStackTraceProgram X(argc, argv);
>   GlobalX = &X;
> }
> // --- in another .CPP file
> PrintStackTraceProgram *GlobalX;
> int foo() { GlobalX->print(...); }
> ```
> And avoid the changes here altogether?
> 
Thank you for the suggestion. This will help in my use case. I will update the patch.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85458/new/

https://reviews.llvm.org/D85458



More information about the llvm-commits mailing list