diff options
author | Daniel Jacobowitz <dan@debian.org> | 2009-06-28 00:20:21 +0000 |
---|---|---|
committer | Daniel Jacobowitz <dan@debian.org> | 2009-06-28 00:20:21 +0000 |
commit | 089afc895b5bcfd814658c61a910ea386120c570 (patch) | |
tree | 3ff2e79f0f5a341f7086be856691dd066a2309f5 /gdb/doc | |
parent | 78a5fe1b7d107c963fae6dc5beaf01a83c1d0cac (diff) | |
download | gdb-089afc895b5bcfd814658c61a910ea386120c570.tar.gz |
gdb/
* NEWS: Document inlined function support.
* Makefile.in (SFILES): Add inline-frame.c.
(COMMON_OBS): Add inline-frame.o.
* block.c (contained_in): Rewrite to use lexical nesting.
(block_linkage_function): Skip inlined function blocks.
(block_inlined_p): New.
* block.h (struct block): Update comment.
(block_inlined_p): New prototype.
* blockframe.c (get_frame_block): Handle inlined functions.
(get_frame_function): Do not use block_linkage_function.
(block_innermost_frame): Use get_frame_block and contained_in.
* breakpoint.c (watchpoint_check): Remove extra reinit_frame_cache.
Skip over inlined functions. Simplify epilogue check.
(bpstat_check_breakpoint_conditions): Use get_stack_frame_id.
Update comments.
(set_momentary_breakpoint): Only accept non-inlined frames.
(watch_command_1): Use frame_unwind_caller_pc and
frame_unwind_caller_id instead of get_prev_frame.
(until_break_command): Likewise. Use get_stack_frame_id.
* buildsym.c (end_symtab): Set SYMBOL_SYMTAB for block functions.
* dwarf2loc.c (dwarf_expr_frame_base): Use block_linkage_function.
* dwarf2read.c (process_die): Handle DW_TAG_inlined_subroutine.
(read_func_scope, new_symbol): Likewise. Handle arguments specially
for inlined functions without call site information.
(inherit_abstract_dies): Allow tag mismatch for inlined subroutines.
(die_specification): Treat DW_AT_abstract_origin as a specification.
(read_type_die): Handle DW_TAG_inlined_subroutine.
* frame-unwind.c (frame_unwind_init): Add inline_frame_unwind.
* frame.c (fprint_frame_id): Print inline depth.
(fprint_frame_type): Handle INLINE_FRAME and SENTINEL_FRAME.
(skip_inlined_frames, get_stack_frame_id): New.
(frame_unwind_caller_id): Use skip_inlined_frames.
(frame_id_inlined_p): New.
(frame_id_eq): Make the logic match the comments. Add inline_depth
check.
(frame_id_inner): Handle inlined functions.
(frame_unwind_pc): New function, copied from frame_unwind_caller_pc.
(frame_unwind_caller_pc): Use skip_inlined_frames and frame_unwind_pc.
(get_prev_frame_1): Check for inline frames. Split out frame
allocation to get_prev_frame_raw.
(get_prev_frame_raw): New function.
(get_prev_frame): Handle inline frames.
(get_frame_pc): Use frame_unwind_pc.
(get_frame_address_in_block): Skip inlined frames on both sides.
(pc_notcurrent): Delete.
(find_frame_sal): Rewrite to handle inline call sites. Use
get_frame_address_in_block.
(deprecated_update_frame_pc_hack): Make static.
* frame.h: Update comments.
(struct frame_id): Add inline_depth.
(enum frame_type): Add INLINE_FRAME.
(frame_id_inlined_p, get_stack_frame_id): New prototypes.
* gdbthread.h (struct thread_info): Add step_stack_frame_id field.
* infcmd.c (set_step_frame): New function.
(step_once): Use set_step_frame. Handle inlined functions.
(until_next_command): Use set_step_frame.
(finish_backward), finish_forward): Use get_stack_frame_id.
(finish_command): Support inlined functions.
* inferior.h (set_step_info): New prototype.
* infrun.c (RESUME_ALL): Use minus_one_ptid.
(clear_proceed_status): Clear step_stack_frame_id.
(init_wait_for_inferior): Call clear_inline_frame_state.
(init_execution_control_state): Make static.
(set_step_info): New function.
(init_thread_stepping_state): Do not set the symtab or line here.
(stepped_in_from): New function.
(handle_inferior_event): Handle inlined functions. Use set_step_info.
(insert_step_resume_breakpoint_at_frame): Use get_stack_frame_id.
(struct inferior_status): Add step_stack_frame_id.
(save_inferior_status, restore_inferior_status): Save and restore
step_stack_frame_id.
* inline-frame.c, inline-frame.h: New files.
* minsyms.c (prim_record_minimal_symbol_and_info): Use XCALLOC.
* regcache.c (regcache_write_pc): Call reinit_frame_cache.
* s390-tdep.c (s390_prologue_frame_unwind_cache): Handle INLINE_FRAME.
* stack.c (frame_show_address): New.
(print_frame_info, print_frame): Use it.
(find_frame_funname): Use get_frame_function. Handle inlined blocks.
(frame_info): Mark inlined functions.
(backtrace_command_1): Use get_current_user_frame.
(print_frame_local_vars, print_frame_label_vars): Update comments.
(return_command): Refuse inlined functions.
* symtab.c (lookup_symbol_aux_local): Stop at inlined function
boundaries.
(find_function_start_sal): Avoid inlined functions.
(completion_list_add_fields): New function.
(default_make_symbol_completion_list): Use it. Use block_static_block
and block_global_block. Check for inlined functions.
(skip_prologue_using_sal): Avoid line number comparison across
inlining.
* symtab.h (struct symbol): Add is_inlined.
(SYMBOL_INLINED): New.
* target.c (target_resume): Call clear_inline_frame_state.
* valops.c (value_of_variable): Check block_inlined_p.
gdb/doc/
* gdb.texinfo (Debugging Optimized Code): New chapter.
(Compiling for Debugging): Reference it. Move some
text to the new section.
gdb/testsuite/
* gdb.base/break.exp: Add an XFAIL for gcc/36748.
* gdb.cp/annota2.exp: Accept frames-invalid in more places.
* gdb.opt/Makefile.in (EXECUTABLES): Update.
* gdb.opt/clobbered-registers-O2.exp: Update to GPL v3.
* gdb.opt/inline-bt.c, gdb.opt/inline-bt.exp,
gdb.opt/inline-cmds.c, gdb.opt/inline-cmds.exp,
gdb.opt/inline-locals.c, gdb.opt/inline-locals.exp,
gdb.opt/inline-markers.c: New files.
* lib/gdb.exp (skip_inline_frame_tests): New function.
(skip_inline_var_tests): New function.
Diffstat (limited to 'gdb/doc')
-rw-r--r-- | gdb/doc/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/doc/gdb.texinfo | 121 |
2 files changed, 110 insertions, 17 deletions
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 972e4588894..26b2aae5133 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,9 @@ +2009-06-27 Daniel Jacobowitz <dan@codesourcery.com> + + * gdb.texinfo (Debugging Optimized Code): New chapter. + (Compiling for Debugging): Reference it. Move some + text to the new section. + 2009-06-15 Phil Muldoon <pmuldoon@redhat.com> * doc/gdb.texinfo (Calling): Document diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 94852ec4dc1..17fc7d63795 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -139,6 +139,7 @@ software in general. We will miss him. * Stack:: Examining the stack * Source:: Examining source files * Data:: Examining data +* Optimized Code:: Debugging optimized code * Macros:: Preprocessor Macros * Tracepoints:: Debugging remote targets non-intrusively * Overlays:: Debugging programs that use overlays @@ -1808,7 +1809,7 @@ To request debugging information, specify the @samp{-g} option when you run the compiler. Programs that are to be shipped to your customers are compiled with -optimizations, using the @samp{-O} compiler option. However, many +optimizations, using the @samp{-O} compiler option. However, some compilers are unable to handle the @samp{-g} and @samp{-O} options together. Using those compilers, you cannot generate optimized executables containing debugging information. @@ -1817,22 +1818,7 @@ executables containing debugging information. without @samp{-O}, making it possible to debug optimized code. We recommend that you @emph{always} use @samp{-g} whenever you compile a program. You may think your program is correct, but there is no sense -in pushing your luck. - -@cindex optimized code, debugging -@cindex debugging optimized code -When you debug a program compiled with @samp{-g -O}, remember that the -optimizer is rearranging your code; the debugger shows you what is -really there. Do not be too surprised when the execution path does not -exactly match your source file! An extreme example: if you define a -variable, but never use it, @value{GDBN} never sees that -variable---because the compiler optimizes it out of existence. - -Some things do not work as well with @samp{-g -O} as with just -@samp{-g}, particularly on machines with instruction scheduling. If in -doubt, recompile with @samp{-g} alone, and if this fixes the problem, -please report it to us as a bug (including a test case!). -@xref{Variables}, for more information about debugging optimized code. +in pushing your luck. For more information, see @ref{Optimized Code}. Older versions of the @sc{gnu} C compiler permitted a variant option @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this @@ -8538,6 +8524,107 @@ $1 = 1 $2 = (void *) 0x8049560 @end smallexample +@node Optimized Code +@chapter Debugging Optimized Code +@cindex optimized code, debugging +@cindex debugging optimized code + +Almost all compilers support optimization. With optimization +disabled, the compiler generates assembly code that corresponds +directly to your source code, in a simplistic way. As the compiler +applies more powerful optimizations, the generated assembly code +diverges from your original source code. With help from debugging +information generated by the compiler, @value{GDBN} can map from +the running program back to constructs from your original source. + +@value{GDBN} is more accurate with optimization disabled. If you +can recompile without optimization, it is easier to follow the +progress of your program during debugging. But, there are many cases +where you may need to debug an optimized version. + +When you debug a program compiled with @samp{-g -O}, remember that the +optimizer has rearranged your code; the debugger shows you what is +really there. Do not be too surprised when the execution path does not +exactly match your source file! An extreme example: if you define a +variable, but never use it, @value{GDBN} never sees that +variable---because the compiler optimizes it out of existence. + +Some things do not work as well with @samp{-g -O} as with just +@samp{-g}, particularly on machines with instruction scheduling. If in +doubt, recompile with @samp{-g} alone, and if this fixes the problem, +please report it to us as a bug (including a test case!). +@xref{Variables}, for more information about debugging optimized code. + +@menu +* Inline Functions:: How @value{GDBN} presents inlining +@end menu + +@node Inline Functions +@section Inline Functions +@cindex inline functions, debugging + +@dfn{Inlining} is an optimization that inserts a copy of the function +body directly at each call site, instead of jumping to a shared +routine. @value{GDBN} displays inlined functions just like +non-inlined functions. They appear in backtraces. You can view their +arguments and local variables, step into them with @code{step}, skip +them with @code{next}, and escape from them with @code{finish}. +You can check whether a function was inlined by using the +@code{info frame} command. + +For @value{GDBN} to support inlined functions, the compiler must +record information about inlining in the debug information --- +@value{NGCC} using the @sc{dwarf 2} format does this, and several +other compilers do also. @value{GDBN} only supports inlined functions +when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1 +do not emit two required attributes (@samp{DW_AT_call_file} and +@samp{DW_AT_call_line}); @value{GDBN} does not display inlined +function calls with earlier versions of @value{NGCC}. It instead +displays the arguments and local variables of inlined functions as +local variables in the caller. + +The body of an inlined function is directly included at its call site; +unlike a non-inlined function, there are no instructions devoted to +the call. @value{GDBN} still pretends that the call site and the +start of the inlined function are different instructions. Stepping to +the call site shows the call site, and then stepping again shows +the first line of the inlined function, even though no additional +instructions are executed. + +This makes source-level debugging much clearer; you can see both the +context of the call and then the effect of the call. Only stepping by +a single instruction using @code{stepi} or @code{nexti} does not do +this; single instruction steps always show the inlined body. + +There are some ways that @value{GDBN} does not pretend that inlined +function calls are the same as normal calls: + +@itemize @bullet +@item +You cannot set breakpoints on inlined functions. @value{GDBN} +either reports that there is no symbol with that name, or else sets the +breakpoint only on non-inlined copies of the function. This limitation +will be removed in a future version of @value{GDBN}; until then, +set a breakpoint by line number on the first line of the inlined +function instead. + +@item +Setting breakpoints at the call site of an inlined function may not +work, because the call site does not contain any code. @value{GDBN} +may incorrectly move the breakpoint to the next line of the enclosing +function, after the call. This limitation will be removed in a future +version of @value{GDBN}; until then, set a breakpoint on an earlier line +or inside the inlined function instead. + +@item +@value{GDBN} cannot locate the return value of inlined calls after +using the @code{finish} command. This is a limitation of compiler-generated +debugging information; after @code{finish}, you can step to the next line +and print a variable where your program stored the return value. + +@end itemize + + @node Macros @chapter C Preprocessor Macros |