This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 2/2] Fix "info frame" in the outermost frame.


On 11/30/2013 04:15 AM, Pedro Alves wrote:
>     CORE_ADDR caller_pc;
> +  volatile struct gdb_exception ex;
>   
>     fi = parse_frame_specification_1 (addr_exp, "No stack.", &selected_frame_p);
>     gdbarch = get_frame_arch (fi);
> @@ -1493,11 +1494,29 @@ frame_info (char *addr_exp, int from_tty)
>   		     sal.line);
>     puts_filtered ("; ");
>     wrap_here ("    ");
> -  printf_filtered ("saved %s ", pc_regname);
> -  if (frame_unwind_caller_pc_if_available (fi, &caller_pc))
> -    fputs_filtered (paddress (gdbarch, caller_pc), gdb_stdout);
> +  printf_filtered ("saved %s = ", pc_regname);
> +
> +  TRY_CATCH (ex, RETURN_MASK_ERROR)
> +    {
> +      caller_pc = frame_unwind_caller_pc (fi);
> +    }
> +  if (ex.reason < 0)
> +    {
> +      switch (ex.error)
> +	{
> +	case NOT_AVAILABLE_ERROR:
> +	  val_print_unavailable (gdb_stdout);
> +	  break;
> +	case OPTIMIZED_OUT_ERROR:
> +	  val_print_not_saved (gdb_stdout);
> +	  break;
> +	default:
> +	  fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
> +	  break;
> +	}
> +    }
>     else
> -    fputs_filtered ("<unavailable>", gdb_stdout);
> +    fputs_filtered (paddress (gdbarch, caller_pc), gdb_stdout);

Subject: [PATCH] Avoid "may be used uninitialized" warning

Hi,
I see such warning below on one compiler I am using.

cc1: warnings being treated as errors
../../workspace/gdb/stack.c: In function 'frame_info':
../../workspace/gdb/stack.c:1519:20: error: 'caller_pc' may be used uninitialized in this function

Go through the gdb-patches archives and find the "canonical" way to
fix this warning is to initialize the variable.  Patch is
pushed.

gdb:

2013-12-08  Yao Qi  <yao@codesourcery.com>

	* stack.c (frame_info): Initialize variable caller_pc.
---
 gdb/ChangeLog |    4 ++++
 gdb/stack.c   |    3 ++-
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4748392..252aa69 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2013-12-08  Yao Qi  <yao@codesourcery.com>
+
+	* stack.c (frame_info): Initialize variable caller_pc.
+
 2013-12-06  Pedro Alves  <palves@redhat.com>
 
 	* frame.c (enum cached_copy_status): New enum.
diff --git a/gdb/stack.c b/gdb/stack.c
index 848bcb0a..f45bb80 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -1407,7 +1407,8 @@ frame_info (char *addr_exp, int from_tty)
   struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
   CORE_ADDR frame_pc;
   int frame_pc_p;
-  CORE_ADDR caller_pc;
+  /* Initialize it to avoid "may be used uninitialized" warning.  */
+  CORE_ADDR caller_pc = 0;
   volatile struct gdb_exception ex;
 
   fi = parse_frame_specification_1 (addr_exp, "No stack.", &selected_frame_p);

-- 
Yao (éå)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]