Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose __sanitizer_print_stack_trace()? #243

Closed
ramosian-glider opened this issue Aug 31, 2015 · 19 comments
Closed

Expose __sanitizer_print_stack_trace()? #243

ramosian-glider opened this issue Aug 31, 2015 · 19 comments

Comments

@ramosian-glider
Copy link
Member

Originally reported on Google Code with ID 243

When I'm hacking Chrome and need to trace a function call, I can do "base::debug::StackTrace().Print()".
However, the stack traces produced by sanitizer tools are much better, and often I
find myself introducing an ASan error just to see the stack trace. This is ugly and
has the unwanted effect of killing the process. Should we perhaps expose an interface
function like __sanitizer_print_stack_trace()?

Reported by earthdok@google.com on 2013-11-14 18:25:29

@ramosian-glider
Copy link
Member Author

go for it!

Reported by konstantin.s.serebryany on 2013-11-15 05:09:18

  • Labels added: Type-Enhancement
  • Labels removed: Type-Defect

@ramosian-glider
Copy link
Member Author

is this done? 

Reported by konstantin.s.serebryany on 2013-12-06 11:20:19

@ramosian-glider
Copy link
Member Author

Currently we only define this function in ASan (which is where I need it). We decided
to wait until the stack unwinding code is generalized enough that this function can
be implemented in sanitizer_common, rather than implement it separately in each tool.
I would keep this open until then.

Reported by earthdok@chromium.org on 2013-12-06 12:15:59

@ramosian-glider
Copy link
Member Author

This function is actually super helpful. There's just one problem. Typically you would
use it something like this:

void Class::Method() {
  fprintf(stderr, "Method() in %p\n", this);
  __sanitizer_print_stack_trace();
  ...
}

But now if I set log_path, the stack traces go in the file and all the additional info
still goes to stderr. This is pretty much useless.

So now we may need to expose __sanitizer_report() as well.

Reported by earthdok@chromium.org on 2013-12-12 21:19:16

@ramosian-glider
Copy link
Member Author

May be even __sanitizer_printf, or have __sanitizer_report accept printf-style format
string (the limited format parsed by internal Printf).

Reported by eugenis@google.com on 2013-12-13 08:33:57

@ramosian-glider
Copy link
Member Author

I think you're over-complicating things. Your use case can be fixed by calling __sanitizer_set_report_path("stderr").
Why should we expose sanitizer logging machinery to the end-user?

Reported by samsonov@google.com on 2013-12-13 09:23:18

@ramosian-glider
Copy link
Member Author

>  Your use case can be fixed by calling __sanitizer_set_report_path("stderr").

In other words, you're suggesting not to use log_path. In Chrome, parsing the output
of several renderers intermixed in the same log is less than fun.

Reported by earthdok@chromium.org on 2013-12-13 11:03:05

@ramosian-glider
Copy link
Member Author

I still find it weird that you essentially use sanitizer runtime for logging. This is
not its purpose. Another way to fix your example - call "fprintf(stderr, "==%d== Method
in %p", getpid(), this)); and match pid to log produced by sanitizer.

Reported by samsonov@google.com on 2013-12-13 11:11:51

@ramosian-glider
Copy link
Member Author

I dunno. Sanitizers are essentially debugging tools, so why not add extra debugging
functionality.

> Another way to fix your example - call "fprintf(stderr, "==%d== Method in %p", getpid(),
this)); and match pid to log produced by sanitizer.

This doesn't help in the example above when I want to see which object the stack trace
is associated with.

Reported by earthdok@chromium.org on 2013-12-13 13:14:53

@ramosian-glider
Copy link
Member Author

Sanitizers are small special-purpose tools for detecting certain kinds of errors. Anyway,
that's just my opinion, let's hear from others. Kostya?

Reported by samsonov@google.com on 2013-12-13 13:18:03

@ramosian-glider
Copy link
Member Author

Can you make void __sanitizer_print_stack_trace(const char *fmt, ...)
which will both print whatever you need to print and then print stack trace?
just make sure that __sanitizer_print_stack_trace(0) works too

Reported by konstantin.s.serebryany on 2013-12-13 13:23:10

@ramosian-glider
Copy link
Member Author

You don't always want to print the stack trace, sometimes you just need a debug print.
But you still want to see the debug output of the process as one stream, with all the
stack traces and without interference from other processes.

I don't *particularly* like the idea of exposing Report() either, but I don't see a
better way to solve this, and moreover I can't come up with a strong case against it.

Reported by earthdok@chromium.org on 2013-12-13 15:14:08

@ramosian-glider
Copy link
Member Author

Ping?

Reported by earthdok@google.com on 2013-12-23 15:22:39

@ramosian-glider
Copy link
Member Author

maybe __sanitizer_print_stack_trace(int max_frames, const char *fmt, ...) ?
With max_frames==0 this turns into Report.
We need max_frames anyway, because printing large number of frames may 
slowdown the program significantly and thus hide a time-sensitive bug. 

Reported by konstantin.s.serebryany on 2013-12-24 07:20:31

@ramosian-glider
Copy link
Member Author

http://llvm.org/viewvc/llvm-project?rev=196302&view=rev added asan implementation.
we don't have msan and tsan variants yet.

Reported by konstantin.s.serebryany on 2014-05-14 13:53:28

@ramosian-glider
Copy link
Member Author

Yes, an MSan implementation would be most welcome. I've had to put fake uninitialized
accesses into Chromium code one too many times...

Reported by earthdok@chromium.org on 2014-05-14 16:25:03

@ramosian-glider
Copy link
Member Author

MSan implementation was added a while ago.
http://llvm.org/viewvc/llvm-project?view=revision&revision=221469 adds TSan implementation.

Reported by samsonov@chromium.org on 2014-11-06 18:55:07

@ramosian-glider
Copy link
Member Author

Reported by samsonov@google.com on 2014-11-06 18:55:35

  • Status changed: Fixed

@ramosian-glider
Copy link
Member Author

Adding Project:AddressSanitizer as part of GitHub migration.

Reported by ramosian.glider on 2015-07-30 09:13:43

  • Labels added: ProjectAddressSanitizer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant