[FYI/pushed] ARI: Add detection of printf_vma and sprintf_vma (was: "Re: [PATCH] gdb/tracepoint.c: Don't use printf_vma")

Message ID 20161119184322.GD4132@adacore.com
State New
Headers show

Commit Message

Joel Brobecker Nov. 19, 2016, 6:43 p.m.
> >> gdb/ChangeLog:

> >> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

> >>

> >> 	* tracepoint.c (collection_list::add_memrange): Add gdbarch

> >> 	parameter.  Use paddress instead of printf_vma.  Adjust recursive

> >> 	calls.

> >> 	(collection_list::stringify): Use paddress and phex_nz instead of

> >> 	sprintf_vma.  Adjust add_memrange call.

> >> 	* tracepoint.h (collection_list::add_memrange): Declare new method.

> > 

> > How about adding an ARI rule for those? I think it would help

> > avoid this function creeping back in.

> 

> Indeed, sounds like a good idea.


Thanks! I just pushed the attached patch to master.

gdb/ChangeLog:

        * contrib/ari/gdb_ari.sh: Add detection of printf_vma and
        sprintf_vma.

-- 
Joel

Patch

From cc188e5fd6d4f8d3061ed6c58c432a150f7966e9 Mon Sep 17 00:00:00 2001
From: Joel Brobecker <brobecker@adacore.com>
Date: Sat, 19 Nov 2016 10:40:17 -0800
Subject: [PATCH] ARI: Add detection of printf_vma and sprintf_vma

We shouldn't be using these, since their output goes straight to
stdout, which doesn't allow redirection. So this patch updates
the ARI to detect any such use.

gdb/ChangeLog:

        * contrib/ari/gdb_ari.sh: Add detection of printf_vma and
        sprintf_vma.
---
 gdb/ChangeLog              |  5 +++++
 gdb/contrib/ari/gdb_ari.sh | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 07d21a6..3797e8b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@ 
+2016-11-19  Joel Brobecker  <brobecker@adacore.com>
+
+	* contrib/ari/gdb_ari.sh: Add detection of printf_vma and
+	sprintf_vma.
+
 2016-11-18  Simon Marchi  <simon.marchi@polymtl.ca>
 
 	* Makefile.in (%.o: $(srcdir)/gdbtk/generic/%.c): Fix typo.
diff --git a/gdb/contrib/ari/gdb_ari.sh b/gdb/contrib/ari/gdb_ari.sh
index 7e639e3..2ecc0d6 100755
--- a/gdb/contrib/ari/gdb_ari.sh
+++ b/gdb/contrib/ari/gdb_ari.sh
@@ -1097,6 +1097,22 @@  Do not use vasprintf(), instead use xstrvprintf"
     fail("vasprintf")
 }
 
+BEGIN { doc["printf_vma"] = "\
+Do not use printf_vma, instead use paddress or phex_nz"
+    category["printf_vma"] = ari_code
+}
+/(^|[^_[:alnum:]])printf_vma[[:space:]]*\(/ {
+    fail("printf_vma")
+}
+
+BEGIN { doc["sprintf_vma"] = "\
+Do not use sprintf_vma, instead use paddress or phex_nz"
+    category["sprintf_vma"] = ari_code
+}
+/(^|[^_[:alnum:]])sprintf_vma[[:space:]]*\(/ {
+    fail("sprintf_vma")
+}
+
 # More generic memory operations
 
 BEGIN { doc["bzero"] = "\
-- 
2.5.0