|
From: Bart V. A. <bar...@gm...> - 2008-01-05 11:33:54
|
> On 05/01/2008, Tom Hughes <to...@co...> wrote:
>
> > On 04/01/2008, Bart Van Assche <bar...@gm...> wrote:
> >
> > The attached patch solves this issue for exp-drd/drd_main.c. Can you
> > please review and apply the attached patch ?
>
> Applied, but is there not a better alternative to hardcoding the stack
> depth to fetch like that?
I'm not entirely happy with hardcoding the stack depth either. Please
note that the problem of hardcoded stack depths does not only exist in
drd but also in other Valgrind tools (helgrind/hg_main.c,
msm__show_state_change()). Other tools (exp-omega) use
VG_(clo_backtrace_size) as stack depth by including coregrind header
files, which should be avoided.
Do you think it would be a good idea to use the stack depth specified
via the --num-callers=... command line option when printing a call
stack ? Unfortunately this value (VG_(clo_backtrace_size)) is not
available to tools. One way to overcome this is to define a special
value for n_ips that selects the stack depth specified via
--num-callers=..., e.g. as follows:
Index: include/pub_tool_stacktrace.h
===================================================================
--- include/pub_tool_stacktrace.h (revision 7318)
+++ include/pub_tool_stacktrace.h (working copy)
@@ -52,8 +52,13 @@
// Print a StackTrace.
extern void VG_(pp_StackTrace) ( StackTrace ips, UInt n_ips );
+
+#define DEFAULT_PP_STACK_DEPTH 0
+
// Gets and immediately prints a StackTrace. Just a bit simpler than
// calling VG_(get_StackTrace)() then VG_(pp_StackTrace)().
+// Specify DEFAULT_PP_STACK_DEPTH for n_ips to print the number of stack frames
+// specified via --num-callers=<number>.
extern void VG_(get_and_pp_StackTrace) ( ThreadId tid, UInt n_ips );
#endif // __PUB_TOOL_STACKTRACE_H
Index: coregrind/m_stacktrace.c
===================================================================
--- coregrind/m_stacktrace.c (revision 7318)
+++ coregrind/m_stacktrace.c (working copy)
@@ -470,10 +470,16 @@
/* Get and immediately print a StackTrace. */
void VG_(get_and_pp_StackTrace) ( ThreadId tid, UInt n_ips )
{
- Addr ips[n_ips];
- UInt n_ips_obtained = VG_(get_StackTrace)(tid, ips, n_ips,
- 0/*first_ip_delta*/);
- VG_(pp_StackTrace)(ips, n_ips_obtained);
+ if (n_ips == DEFAULT_PP_STACK_DEPTH)
+ {
+ n_ips = VG_(clo_backtrace_size);
+ }
+ {
+ Addr ips[n_ips];
+ UInt n_ips_obtained = VG_(get_StackTrace)(tid, ips, n_ips,
+ 0/*first_ip_delta*/);
+ VG_(pp_StackTrace)(ips, n_ips_obtained);
+ }
}
|