[1/2] addr2line: new option -n to add a newline at the end

Message ID 20221219135303.116222-2-mpapini@redhat.com
State Accepted
Headers
Series addr2line: new option -n to add a newline at the end |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

Maurizio Papini Dec. 19, 2022, 1:53 p.m. UTC
  ---
 binutils/addr2line.c       | 11 +++++++++--
 binutils/doc/binutils.texi |  5 +++++
 2 files changed, 14 insertions(+), 2 deletions(-)
  

Patch

diff --git a/binutils/addr2line.c b/binutils/addr2line.c
index baf16716182..d9338e9f1ea 100644
--- a/binutils/addr2line.c
+++ b/binutils/addr2line.c
@@ -45,7 +45,7 @@  static bool with_functions;	/* -f, show function names.  */
 static bool do_demangle;	/* -C, demangle names.  */
 static bool pretty_print;	/* -p, print on one line.  */
 static bool base_names;		/* -s, strip directory names.  */
-
+static bool add_newline;        /* -n, add a newline at the end. */
 /* Flags passed to the name demangler.  */
 static int demangle_flags = DMGL_PARAMS | DMGL_ANSI;
 
@@ -70,6 +70,7 @@  static struct option long_options[] =
   {"no-recursion-limit", no_argument, NULL, 'r'},  
   {"section", required_argument, NULL, 'j'},
   {"target", required_argument, NULL, 'b'},
+  {"add-newline", no_argument, NULL, 'n'},
   {"help", no_argument, NULL, 'H'},
   {"version", no_argument, NULL, 'V'},
   {0, no_argument, 0, 0}
@@ -102,6 +103,7 @@  usage (FILE *stream, int status)
   -C --demangle[=style]  Demangle function names\n\
   -R --recurse-limit     Enable a limit on recursion whilst demangling.  [Default]\n\
   -r --no-recurse-limit  Disable a limit on recursion whilst demangling\n\
+  -n --add-newline       Add a newline at the end of the output\n\
   -h --help              Display this information\n\
   -v --version           Display the program's version\n\
 \n"));
@@ -417,6 +419,8 @@  translate_addresses (bfd *abfd, asection *section)
             }
 	}
 
+      if(add_newline)
+        printf("\n");
       /* fflush() is essential for using this command as a server
          child process that reads addresses from a pipe and responds
          with line number information, processing one address at a
@@ -505,7 +509,7 @@  main (int argc, char **argv)
   file_name = NULL;
   section_name = NULL;
   target = NULL;
-  while ((c = getopt_long (argc, argv, "ab:Ce:rRsfHhij:pVv", long_options, (int *) 0))
+  while ((c = getopt_long (argc, argv, "ab:Ce:rRsfnHhij:pVv", long_options, (int *) 0))
 	 != EOF)
     {
       switch (c)
@@ -564,6 +568,9 @@  main (int argc, char **argv)
 	case 'j':
 	  section_name = optarg;
 	  break;
+  case 'n':
+    add_newline = true;
+    break;
 	default:
 	  usage (stderr, 1);
 	  break;
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index c9d52d7c92f..0940708d77e 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -3976,6 +3976,7 @@  addr2line [@option{-a}|@option{--addresses}]
           [@option{-f}|@option{--functions}] [@option{-s}|@option{--basename}]
           [@option{-i}|@option{--inlines}]
           [@option{-p}|@option{--pretty-print}]
+          [@option{-n}|@option{--add-newline}]
           [@option{-j}|@option{--section=}@var{name}]
           [@option{-H}|@option{--help}] [@option{-V}|@option{--version}]
           [addr addr @dots{}]
@@ -4102,6 +4103,10 @@  Make the output more human friendly: each location are printed on one line.
 If option @option{-i} is specified, lines for all enclosing scopes are
 prefixed with @samp{(inlined by)}.
 
+@item -n
+@itemx --add-newline
+Add a newline at the end of the output.
+
 @item -r
 @itemx -R
 @itemx --recurse-limit