You can subscribe to this list here.
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
(122) |
Nov
(152) |
Dec
(69) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2003 |
Jan
(6) |
Feb
(25) |
Mar
(73) |
Apr
(82) |
May
(24) |
Jun
(25) |
Jul
(10) |
Aug
(11) |
Sep
(10) |
Oct
(54) |
Nov
(203) |
Dec
(182) |
| 2004 |
Jan
(307) |
Feb
(305) |
Mar
(430) |
Apr
(312) |
May
(187) |
Jun
(342) |
Jul
(487) |
Aug
(637) |
Sep
(336) |
Oct
(373) |
Nov
(441) |
Dec
(210) |
| 2005 |
Jan
(385) |
Feb
(480) |
Mar
(636) |
Apr
(544) |
May
(679) |
Jun
(625) |
Jul
(810) |
Aug
(838) |
Sep
(634) |
Oct
(521) |
Nov
(965) |
Dec
(543) |
| 2006 |
Jan
(494) |
Feb
(431) |
Mar
(546) |
Apr
(411) |
May
(406) |
Jun
(322) |
Jul
(256) |
Aug
(401) |
Sep
(345) |
Oct
(542) |
Nov
(308) |
Dec
(481) |
| 2007 |
Jan
(427) |
Feb
(326) |
Mar
(367) |
Apr
(255) |
May
(244) |
Jun
(204) |
Jul
(223) |
Aug
(231) |
Sep
(354) |
Oct
(374) |
Nov
(497) |
Dec
(362) |
| 2008 |
Jan
(322) |
Feb
(482) |
Mar
(658) |
Apr
(422) |
May
(476) |
Jun
(396) |
Jul
(455) |
Aug
(267) |
Sep
(280) |
Oct
(253) |
Nov
(232) |
Dec
(304) |
| 2009 |
Jan
(486) |
Feb
(470) |
Mar
(458) |
Apr
(423) |
May
(696) |
Jun
(461) |
Jul
(551) |
Aug
(575) |
Sep
(134) |
Oct
(110) |
Nov
(157) |
Dec
(102) |
| 2010 |
Jan
(226) |
Feb
(86) |
Mar
(147) |
Apr
(117) |
May
(107) |
Jun
(203) |
Jul
(193) |
Aug
(238) |
Sep
(300) |
Oct
(246) |
Nov
(23) |
Dec
(75) |
| 2011 |
Jan
(133) |
Feb
(195) |
Mar
(315) |
Apr
(200) |
May
(267) |
Jun
(293) |
Jul
(353) |
Aug
(237) |
Sep
(278) |
Oct
(611) |
Nov
(274) |
Dec
(260) |
| 2012 |
Jan
(303) |
Feb
(391) |
Mar
(417) |
Apr
(441) |
May
(488) |
Jun
(655) |
Jul
(590) |
Aug
(610) |
Sep
(526) |
Oct
(478) |
Nov
(359) |
Dec
(372) |
| 2013 |
Jan
(467) |
Feb
(226) |
Mar
(391) |
Apr
(281) |
May
(299) |
Jun
(252) |
Jul
(311) |
Aug
(352) |
Sep
(481) |
Oct
(571) |
Nov
(222) |
Dec
(231) |
| 2014 |
Jan
(185) |
Feb
(329) |
Mar
(245) |
Apr
(238) |
May
(281) |
Jun
(399) |
Jul
(382) |
Aug
(500) |
Sep
(579) |
Oct
(435) |
Nov
(487) |
Dec
(256) |
| 2015 |
Jan
(338) |
Feb
(357) |
Mar
(330) |
Apr
(294) |
May
(191) |
Jun
(108) |
Jul
(142) |
Aug
(261) |
Sep
(190) |
Oct
(54) |
Nov
(83) |
Dec
(22) |
| 2016 |
Jan
(49) |
Feb
(89) |
Mar
(33) |
Apr
(50) |
May
(27) |
Jun
(34) |
Jul
(53) |
Aug
(53) |
Sep
(98) |
Oct
(206) |
Nov
(93) |
Dec
(53) |
| 2017 |
Jan
(65) |
Feb
(82) |
Mar
(102) |
Apr
(86) |
May
(187) |
Jun
(67) |
Jul
(23) |
Aug
(93) |
Sep
(65) |
Oct
(45) |
Nov
(35) |
Dec
(17) |
| 2018 |
Jan
(26) |
Feb
(35) |
Mar
(38) |
Apr
(32) |
May
(8) |
Jun
(43) |
Jul
(27) |
Aug
(30) |
Sep
(43) |
Oct
(42) |
Nov
(38) |
Dec
(67) |
| 2019 |
Jan
(32) |
Feb
(37) |
Mar
(53) |
Apr
(64) |
May
(49) |
Jun
(18) |
Jul
(14) |
Aug
(53) |
Sep
(25) |
Oct
(30) |
Nov
(49) |
Dec
(31) |
| 2020 |
Jan
(87) |
Feb
(45) |
Mar
(37) |
Apr
(51) |
May
(99) |
Jun
(36) |
Jul
(11) |
Aug
(14) |
Sep
(20) |
Oct
(24) |
Nov
(40) |
Dec
(23) |
| 2021 |
Jan
(14) |
Feb
(53) |
Mar
(85) |
Apr
(15) |
May
(19) |
Jun
(3) |
Jul
(14) |
Aug
(1) |
Sep
(57) |
Oct
(73) |
Nov
(56) |
Dec
(22) |
| 2022 |
Jan
(3) |
Feb
(22) |
Mar
(6) |
Apr
(55) |
May
(46) |
Jun
(39) |
Jul
(15) |
Aug
(9) |
Sep
(11) |
Oct
(34) |
Nov
(20) |
Dec
(36) |
| 2023 |
Jan
(79) |
Feb
(41) |
Mar
(99) |
Apr
(169) |
May
(48) |
Jun
(16) |
Jul
(16) |
Aug
(57) |
Sep
(19) |
Oct
|
Nov
|
Dec
|
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
|
|
|
|
|
1
|
2
|
3
|
|
4
(1) |
5
(1) |
6
(5) |
7
|
8
|
9
|
10
|
|
11
|
12
|
13
|
14
(3) |
15
(2) |
16
(3) |
17
|
|
18
|
19
(2) |
20
(7) |
21
(2) |
22
(7) |
23
|
24
|
|
25
(2) |
26
|
27
|
28
(1) |
29
|
30
(2) |
|
|
From: Nicholas N. <nj...@so...> - 2018-11-16 05:49:17
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=18d4bf8f0cbee0f47e35258b34e88a19c5da33fa commit 18d4bf8f0cbee0f47e35258b34e88a19c5da33fa Author: Nicholas Nethercote <nne...@mo...> Date: Fri Nov 16 16:48:13 2018 +1100 Fix Cachegrind's --help message. Diff: --- cachegrind/cg_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cachegrind/cg_main.c b/cachegrind/cg_main.c index f23b82b..cb696b8 100644 --- a/cachegrind/cg_main.c +++ b/cachegrind/cg_main.c @@ -1760,8 +1760,8 @@ static void cg_print_usage(void) { VG_(print_cache_clo_opts)(); VG_(printf)( -" --cache-sim=yes|no [yes] collect cache stats?\n" -" --branch-sim=yes|no [no] collect branch prediction stats?\n" +" --cache-sim=yes|no collect cache stats? [yes]\n" +" --branch-sim=yes|no collect branch prediction stats? [no]\n" " --cachegrind-out-file=<file> output file name [cachegrind.out.%%p]\n" ); } |
|
From: Bart V. A. <bva...@ac...> - 2018-11-15 19:00:37
|
On Thu, 2018-11-15 at 19:39 +0100, Andreas Arnez wrote: > diff --git a/.dir-locals.el b/.dir-locals.el > new file mode 100644 > index 000000000..b65c7a3fb > --- /dev/null > +++ b/.dir-locals.el > @@ -0,0 +1,18 @@ > +;; Emacs settings. > + > +( > + ;; Format used to turn a bug number into a URL (when displaying it). > + (nil . ((bug-reference-url-format . "http://bugs.kde.org/show_bug.cgi?id=%s"))) > + > + ;; Standard settings for editing C source files. > + (c-mode . ( > + ;; Apply the Linux style as a base. > + (c-file-style . "linux") > + ;; Use spaces instead of tabs for indentation. > + (indent-tabs-mode . nil) > + ;; Indent 3 columns per level. > + (c-basic-offset . 3) > + ;; Lines should be limited to 80 columns. > + (fill-column . 80) > + )) > +) Although I think adding a .dir-locals.el file is a good idea, these settings do not match the current indentation for all source files. Some time ago I added the following to my ~/.emacs file (this may be incomplete): (dir-locals-set-class-variables 'valgrind '((c-mode . ((c-basic-offset . 3) (c-label-minimum-indentation . 0) (indent-tabs-mode . nil))))) (dir-locals-set-class-variables 'valgrind-test '((c-mode . ((c-basic-offset . 2) (c-label-minimum-indentation . 0) (indent-tabs-mode . nil))))) (dir-locals-set-directory-class (substitute-in-file-name "$HOME/software/valgrind.git/") 'valgrind) (dir-locals-set-directory-class (substitute-in-file-name "$HOME/software/valgrind.git/drd/tests/") 'valgrind-test) Bart. |
|
From: Andreas A. <ar...@li...> - 2018-11-15 18:40:05
|
When editing source files, I prefer the editor (in my case Emacs) to know the project's basic formatting rules, so I can use auto-indentation, highlighting of whitespace formatting errors, and similar features. For instance, in the case of C source files in the Valgrind source tree, the editor should use an indentation width of 3 columns per level, and it should avoid tabs for indentation. There are multiple ways to tell the editor about this. One way is to change the editor's global settings, in which case the editor will apply them to all source files of all projects. Another way is to enrich source files with a special comment at the top, like this: /* -*- mode: C; c-basic-offset: 3; -*- */ (Which obviously just applies to the source file the comment appears in.) Another way is to place a configuration file at the top of the project's source tree. I have been using such a configuration file for Emacs, ".dir-locals.el", in my local Valgrind source tree for some time now, but it is probably a good idea to include this upstream. Thus I propose the patch below. Note that this is for Emacs only; other editors will probably require additional such files. For instance, https://editorconfig.org/ defines a generic format that seems to be supported by many editors, although Emacs and Vim currently require plugins for this to work. I shortly discussed this topic on IRC with Julian yesterday, and he was wondering about the c-file-style setting (see patch below). I'm not sure about that either; I just considered "Linux" to be the best fit here. If anybody knows a better approach, please let me know. -- >8 -- Subject: [PATCH] Add Emacs configuration file This adds a configuration file for Emacs, ".dir-locals.el", to the topmost directory of the Valgrind source tree. The file contains per-directory local variables. Its settings are applied whenever editing a source file in the Valgrind source tree. --- .dir-locals.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .dir-locals.el diff --git a/.dir-locals.el b/.dir-locals.el new file mode 100644 index 000000000..b65c7a3fb --- /dev/null +++ b/.dir-locals.el @@ -0,0 +1,18 @@ +;; Emacs settings. + +( + ;; Format used to turn a bug number into a URL (when displaying it). + (nil . ((bug-reference-url-format . "http://bugs.kde.org/show_bug.cgi?id=%s"))) + + ;; Standard settings for editing C source files. + (c-mode . ( + ;; Apply the Linux style as a base. + (c-file-style . "linux") + ;; Use spaces instead of tabs for indentation. + (indent-tabs-mode . nil) + ;; Indent 3 columns per level. + (c-basic-offset . 3) + ;; Lines should be limited to 80 columns. + (fill-column . 80) + )) +) -- 2.17.0 |
|
From: Andreas A. <ar...@so...> - 2018-11-14 15:29:38
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=50bd2282bce101012a5668b670cb185375600d2d commit 50bd2282bce101012a5668b670cb185375600d2d Author: Andreas Arnez <ar...@li...> Date: Thu Oct 18 17:51:57 2018 +0200 Bug 397187 s390x: Add vector register support for vgdb On s390x machines with a vector facility, Valgrind's gdbserver didn't represent the vector registers. This is fixed. Diff: --- NEWS | 1 + coregrind/Makefile.am | 5 ++ coregrind/m_gdbserver/s390-vx-valgrind-s1.xml | 43 ++++++++++ coregrind/m_gdbserver/s390-vx-valgrind-s2.xml | 43 ++++++++++ coregrind/m_gdbserver/s390-vx.xml | 59 ++++++++++++++ coregrind/m_gdbserver/s390x-vx-linux-valgrind.xml | 28 +++++++ coregrind/m_gdbserver/s390x-vx-linux.xml | 18 +++++ coregrind/m_gdbserver/valgrind-low-s390x.c | 97 +++++++++++++++++++++-- 8 files changed, 288 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index e0917e2..2fa2c86 100644 --- a/NEWS +++ b/NEWS @@ -49,6 +49,7 @@ where XXXXXX is the bug number as listed below. 399322 Improve callgrind_annotate output 400490 s390x: VRs allocated as if separate from FPRs 400491 s390x: Operand of LOCH treated as unsigned integer +397187 z13 vector register support for vgdb gdbserver Release 3.14.0 (9 October 2018) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/coregrind/Makefile.am b/coregrind/Makefile.am index 8de1996..94030fd 100644 --- a/coregrind/Makefile.am +++ b/coregrind/Makefile.am @@ -685,6 +685,11 @@ GDBSERVER_XML_FILES = \ m_gdbserver/s390x-linux64-valgrind-s1.xml \ m_gdbserver/s390x-linux64-valgrind-s2.xml \ m_gdbserver/s390x-linux64.xml \ + m_gdbserver/s390-vx-valgrind-s1.xml \ + m_gdbserver/s390-vx-valgrind-s2.xml \ + m_gdbserver/s390-vx.xml \ + m_gdbserver/s390x-vx-linux-valgrind.xml \ + m_gdbserver/s390x-vx-linux.xml \ m_gdbserver/mips-cp0-valgrind-s1.xml \ m_gdbserver/mips-cp0-valgrind-s2.xml \ m_gdbserver/mips-cp0.xml \ diff --git a/coregrind/m_gdbserver/s390-vx-valgrind-s1.xml b/coregrind/m_gdbserver/s390-vx-valgrind-s1.xml new file mode 100644 index 0000000..ca461b3 --- /dev/null +++ b/coregrind/m_gdbserver/s390-vx-valgrind-s1.xml @@ -0,0 +1,43 @@ +<?xml version="1.0"?> +<!-- Copyright (C) 2015-2018 Free Software Foundation, Inc. + + Copying and distribution of this file, with or without modification, + are permitted in any medium without royalty provided the copyright + notice and this notice are preserved. --> + +<!DOCTYPE feature SYSTEM "gdb-target.dtd"> +<feature name="org.gnu.gdb.s390.vx-valgrind-s1"> + <reg name="v0ls1" bitsize="64" type="uint64"/> + <reg name="v1ls1" bitsize="64" type="uint64"/> + <reg name="v2ls1" bitsize="64" type="uint64"/> + <reg name="v3ls1" bitsize="64" type="uint64"/> + <reg name="v4ls1" bitsize="64" type="uint64"/> + <reg name="v5ls1" bitsize="64" type="uint64"/> + <reg name="v6ls1" bitsize="64" type="uint64"/> + <reg name="v7ls1" bitsize="64" type="uint64"/> + <reg name="v8ls1" bitsize="64" type="uint64"/> + <reg name="v9ls1" bitsize="64" type="uint64"/> + <reg name="v10ls1" bitsize="64" type="uint64"/> + <reg name="v11ls1" bitsize="64" type="uint64"/> + <reg name="v12ls1" bitsize="64" type="uint64"/> + <reg name="v13ls1" bitsize="64" type="uint64"/> + <reg name="v14ls1" bitsize="64" type="uint64"/> + <reg name="v15ls1" bitsize="64" type="uint64"/> + + <reg name="v16s1" bitsize="128" type="uint128"/> + <reg name="v17s1" bitsize="128" type="uint128"/> + <reg name="v18s1" bitsize="128" type="uint128"/> + <reg name="v19s1" bitsize="128" type="uint128"/> + <reg name="v20s1" bitsize="128" type="uint128"/> + <reg name="v21s1" bitsize="128" type="uint128"/> + <reg name="v22s1" bitsize="128" type="uint128"/> + <reg name="v23s1" bitsize="128" type="uint128"/> + <reg name="v24s1" bitsize="128" type="uint128"/> + <reg name="v25s1" bitsize="128" type="uint128"/> + <reg name="v26s1" bitsize="128" type="uint128"/> + <reg name="v27s1" bitsize="128" type="uint128"/> + <reg name="v28s1" bitsize="128" type="uint128"/> + <reg name="v29s1" bitsize="128" type="uint128"/> + <reg name="v30s1" bitsize="128" type="uint128"/> + <reg name="v31s1" bitsize="128" type="uint128"/> +</feature> diff --git a/coregrind/m_gdbserver/s390-vx-valgrind-s2.xml b/coregrind/m_gdbserver/s390-vx-valgrind-s2.xml new file mode 100644 index 0000000..eccbd8d --- /dev/null +++ b/coregrind/m_gdbserver/s390-vx-valgrind-s2.xml @@ -0,0 +1,43 @@ +<?xml version="1.0"?> +<!-- Copyright (C) 2015-2018 Free Software Foundation, Inc. + + Copying and distribution of this file, with or without modification, + are permitted in any medium without royalty provided the copyright + notice and this notice are preserved. --> + +<!DOCTYPE feature SYSTEM "gdb-target.dtd"> +<feature name="org.gnu.gdb.s390.vx-valgrind-s2"> + <reg name="v0ls2" bitsize="64" type="uint64"/> + <reg name="v1ls2" bitsize="64" type="uint64"/> + <reg name="v2ls2" bitsize="64" type="uint64"/> + <reg name="v3ls2" bitsize="64" type="uint64"/> + <reg name="v4ls2" bitsize="64" type="uint64"/> + <reg name="v5ls2" bitsize="64" type="uint64"/> + <reg name="v6ls2" bitsize="64" type="uint64"/> + <reg name="v7ls2" bitsize="64" type="uint64"/> + <reg name="v8ls2" bitsize="64" type="uint64"/> + <reg name="v9ls2" bitsize="64" type="uint64"/> + <reg name="v10ls2" bitsize="64" type="uint64"/> + <reg name="v11ls2" bitsize="64" type="uint64"/> + <reg name="v12ls2" bitsize="64" type="uint64"/> + <reg name="v13ls2" bitsize="64" type="uint64"/> + <reg name="v14ls2" bitsize="64" type="uint64"/> + <reg name="v15ls2" bitsize="64" type="uint64"/> + + <reg name="v16s2" bitsize="128" type="uint128"/> + <reg name="v17s2" bitsize="128" type="uint128"/> + <reg name="v18s2" bitsize="128" type="uint128"/> + <reg name="v19s2" bitsize="128" type="uint128"/> + <reg name="v20s2" bitsize="128" type="uint128"/> + <reg name="v21s2" bitsize="128" type="uint128"/> + <reg name="v22s2" bitsize="128" type="uint128"/> + <reg name="v23s2" bitsize="128" type="uint128"/> + <reg name="v24s2" bitsize="128" type="uint128"/> + <reg name="v25s2" bitsize="128" type="uint128"/> + <reg name="v26s2" bitsize="128" type="uint128"/> + <reg name="v27s2" bitsize="128" type="uint128"/> + <reg name="v28s2" bitsize="128" type="uint128"/> + <reg name="v29s2" bitsize="128" type="uint128"/> + <reg name="v30s2" bitsize="128" type="uint128"/> + <reg name="v31s2" bitsize="128" type="uint128"/> +</feature> diff --git a/coregrind/m_gdbserver/s390-vx.xml b/coregrind/m_gdbserver/s390-vx.xml new file mode 100644 index 0000000..2a16873 --- /dev/null +++ b/coregrind/m_gdbserver/s390-vx.xml @@ -0,0 +1,59 @@ +<?xml version="1.0"?> +<!-- Copyright (C) 2015-2018 Free Software Foundation, Inc. + + Copying and distribution of this file, with or without modification, + are permitted in any medium without royalty provided the copyright + notice and this notice are preserved. --> + +<!DOCTYPE feature SYSTEM "gdb-target.dtd"> +<feature name="org.gnu.gdb.s390.vx"> + <vector id="v4f" type="ieee_single" count="4"/> + <vector id="v2d" type="ieee_double" count="2"/> + <vector id="v16i8" type="int8" count="16"/> + <vector id="v8i16" type="int16" count="8"/> + <vector id="v4i32" type="int32" count="4"/> + <vector id="v2i64" type="int64" count="2"/> + <union id="vec128"> + <field name="v4_float" type="v4f"/> + <field name="v2_double" type="v2d"/> + <field name="v16_int8" type="v16i8"/> + <field name="v8_int16" type="v8i16"/> + <field name="v4_int32" type="v4i32"/> + <field name="v2_int64" type="v2i64"/> + <field name="uint128" type="uint128"/> + </union> + + <reg name="v0l" bitsize="64" type="uint64"/> + <reg name="v1l" bitsize="64" type="uint64"/> + <reg name="v2l" bitsize="64" type="uint64"/> + <reg name="v3l" bitsize="64" type="uint64"/> + <reg name="v4l" bitsize="64" type="uint64"/> + <reg name="v5l" bitsize="64" type="uint64"/> + <reg name="v6l" bitsize="64" type="uint64"/> + <reg name="v7l" bitsize="64" type="uint64"/> + <reg name="v8l" bitsize="64" type="uint64"/> + <reg name="v9l" bitsize="64" type="uint64"/> + <reg name="v10l" bitsize="64" type="uint64"/> + <reg name="v11l" bitsize="64" type="uint64"/> + <reg name="v12l" bitsize="64" type="uint64"/> + <reg name="v13l" bitsize="64" type="uint64"/> + <reg name="v14l" bitsize="64" type="uint64"/> + <reg name="v15l" bitsize="64" type="uint64"/> + + <reg name="v16" bitsize="128" type="vec128"/> + <reg name="v17" bitsize="128" type="vec128"/> + <reg name="v18" bitsize="128" type="vec128"/> + <reg name="v19" bitsize="128" type="vec128"/> + <reg name="v20" bitsize="128" type="vec128"/> + <reg name="v21" bitsize="128" type="vec128"/> + <reg name="v22" bitsize="128" type="vec128"/> + <reg name="v23" bitsize="128" type="vec128"/> + <reg name="v24" bitsize="128" type="vec128"/> + <reg name="v25" bitsize="128" type="vec128"/> + <reg name="v26" bitsize="128" type="vec128"/> + <reg name="v27" bitsize="128" type="vec128"/> + <reg name="v28" bitsize="128" type="vec128"/> + <reg name="v29" bitsize="128" type="vec128"/> + <reg name="v30" bitsize="128" type="vec128"/> + <reg name="v31" bitsize="128" type="vec128"/> +</feature> diff --git a/coregrind/m_gdbserver/s390x-vx-linux-valgrind.xml b/coregrind/m_gdbserver/s390x-vx-linux-valgrind.xml new file mode 100644 index 0000000..0237002 --- /dev/null +++ b/coregrind/m_gdbserver/s390x-vx-linux-valgrind.xml @@ -0,0 +1,28 @@ +<?xml version="1.0"?> +<!-- Copyright (C) 2010-2018 Free Software Foundation, Inc. + + Copying and distribution of this file, with or without modification, + are permitted in any medium without royalty provided the copyright + notice and this notice are preserved. --> + +<!-- S/390 64-bit user-level code. --> + +<!DOCTYPE target SYSTEM "gdb-target.dtd"> +<target> + <architecture>s390:64-bit</architecture> + <xi:include href="s390x-core64.xml"/> + <xi:include href="s390-acr.xml"/> + <xi:include href="s390-fpr.xml"/> + <xi:include href="s390x-linux64.xml"/> + <xi:include href="s390-vx.xml"/> + <xi:include href="s390x-core64-valgrind-s1.xml"/> + <xi:include href="s390-acr-valgrind-s1.xml"/> + <xi:include href="s390-fpr-valgrind-s1.xml"/> + <xi:include href="s390x-linux64-valgrind-s1.xml"/> + <xi:include href="s390-vx-valgrind-s1.xml"/> + <xi:include href="s390x-core64-valgrind-s2.xml"/> + <xi:include href="s390-acr-valgrind-s2.xml"/> + <xi:include href="s390-fpr-valgrind-s2.xml"/> + <xi:include href="s390x-linux64-valgrind-s2.xml"/> + <xi:include href="s390-vx-valgrind-s2.xml"/> +</target> diff --git a/coregrind/m_gdbserver/s390x-vx-linux.xml b/coregrind/m_gdbserver/s390x-vx-linux.xml new file mode 100644 index 0000000..e431c5b --- /dev/null +++ b/coregrind/m_gdbserver/s390x-vx-linux.xml @@ -0,0 +1,18 @@ +<?xml version="1.0"?> +<!-- Copyright (C) 2010-2018 Free Software Foundation, Inc. + + Copying and distribution of this file, with or without modification, + are permitted in any medium without royalty provided the copyright + notice and this notice are preserved. --> + +<!-- S/390 64-bit user-level code. --> + +<!DOCTYPE target SYSTEM "gdb-target.dtd"> +<target> + <architecture>s390:64-bit</architecture> + <xi:include href="s390x-core64.xml"/> + <xi:include href="s390-acr.xml"/> + <xi:include href="s390-fpr.xml"/> + <xi:include href="s390x-linux64.xml"/> + <xi:include href="s390-vx.xml"/> +</target> diff --git a/coregrind/m_gdbserver/valgrind-low-s390x.c b/coregrind/m_gdbserver/valgrind-low-s390x.c index 7bbb2e3..a667f4b 100644 --- a/coregrind/m_gdbserver/valgrind-low-s390x.c +++ b/coregrind/m_gdbserver/valgrind-low-s390x.c @@ -88,9 +88,42 @@ static struct reg regs[] = { { "f14", 2592, 64 }, { "f15", 2656, 64 }, { "orig_r2", 2720, 64 }, + { "v0l", 2784, 64 }, + { "v1l", 2848, 64 }, + { "v2l", 2912, 64 }, + { "v3l", 2976, 64 }, + { "v4l", 3040, 64 }, + { "v5l", 3104, 64 }, + { "v6l", 3168, 64 }, + { "v7l", 3232, 64 }, + { "v8l", 3296, 64 }, + { "v9l", 3360, 64 }, + { "v10l", 3424, 64 }, + { "v11l", 3488, 64 }, + { "v12l", 3552, 64 }, + { "v13l", 3616, 64 }, + { "v14l", 3680, 64 }, + { "v15l", 3744, 64 }, + { "v16", 3808, 128 }, + { "v17", 3936, 128 }, + { "v18", 4064, 128 }, + { "v19", 4192, 128 }, + { "v20", 4320, 128 }, + { "v21", 4448, 128 }, + { "v22", 4576, 128 }, + { "v23", 4704, 128 }, + { "v24", 4832, 128 }, + { "v25", 4960, 128 }, + { "v26", 5088, 128 }, + { "v27", 5216, 128 }, + { "v28", 5344, 128 }, + { "v29", 5472, 128 }, + { "v30", 5600, 128 }, + { "v31", 5728, 128 }, }; static const char *expedite_regs[] = { "r14", "r15", "pswa", 0 }; -#define num_regs (sizeof (regs) / sizeof (regs[0])) +#define num_regs_all (sizeof (regs) / sizeof (regs[0])) +static int num_regs; static CORE_ADDR get_pc (void) @@ -165,7 +198,7 @@ void transfer_register (ThreadId tid, int abs_regno, void * buf, case 32: VG_(transfer) (&s390x->guest_a14, buf, dir, size, mod); break; case 33: VG_(transfer) (&s390x->guest_a15, buf, dir, size, mod); break; case 34: VG_(transfer) (&s390x->guest_fpc, buf, dir, size, mod); break; - case 35: VG_(transfer) (&s390x->guest_v0, buf, dir, size, mod); break; + case 35: VG_(transfer) (&s390x->guest_v0.w64[0], buf, dir, size, mod); break; case 36: VG_(transfer) (&s390x->guest_v1.w64[0], buf, dir, size, mod); break; case 37: VG_(transfer) (&s390x->guest_v2.w64[0], buf, dir, size, mod); break; case 38: VG_(transfer) (&s390x->guest_v3.w64[0], buf, dir, size, mod); break; @@ -182,18 +215,65 @@ void transfer_register (ThreadId tid, int abs_regno, void * buf, case 49: VG_(transfer) (&s390x->guest_v14.w64[0], buf, dir, size, mod); break; case 50: VG_(transfer) (&s390x->guest_v15.w64[0], buf, dir, size, mod); break; case 51: *mod = False; break; //GDBTD??? { "orig_r2", 0, 64 }, + case 52: VG_(transfer) (&s390x->guest_v0.w64[1], buf, dir, size, mod); break; + case 53: VG_(transfer) (&s390x->guest_v1.w64[1], buf, dir, size, mod); break; + case 54: VG_(transfer) (&s390x->guest_v2.w64[1], buf, dir, size, mod); break; + case 55: VG_(transfer) (&s390x->guest_v3.w64[1], buf, dir, size, mod); break; + case 56: VG_(transfer) (&s390x->guest_v4.w64[1], buf, dir, size, mod); break; + case 57: VG_(transfer) (&s390x->guest_v5.w64[1], buf, dir, size, mod); break; + case 58: VG_(transfer) (&s390x->guest_v6.w64[1], buf, dir, size, mod); break; + case 59: VG_(transfer) (&s390x->guest_v7.w64[1], buf, dir, size, mod); break; + case 60: VG_(transfer) (&s390x->guest_v8.w64[1], buf, dir, size, mod); break; + case 61: VG_(transfer) (&s390x->guest_v9.w64[1], buf, dir, size, mod); break; + case 62: VG_(transfer) (&s390x->guest_v10.w64[1], buf, dir, size, mod); break; + case 63: VG_(transfer) (&s390x->guest_v11.w64[1], buf, dir, size, mod); break; + case 64: VG_(transfer) (&s390x->guest_v12.w64[1], buf, dir, size, mod); break; + case 65: VG_(transfer) (&s390x->guest_v13.w64[1], buf, dir, size, mod); break; + case 66: VG_(transfer) (&s390x->guest_v14.w64[1], buf, dir, size, mod); break; + case 67: VG_(transfer) (&s390x->guest_v15.w64[1], buf, dir, size, mod); break; + case 68: VG_(transfer) (&s390x->guest_v16, buf, dir, size, mod); break; + case 69: VG_(transfer) (&s390x->guest_v17, buf, dir, size, mod); break; + case 70: VG_(transfer) (&s390x->guest_v18, buf, dir, size, mod); break; + case 71: VG_(transfer) (&s390x->guest_v19, buf, dir, size, mod); break; + case 72: VG_(transfer) (&s390x->guest_v20, buf, dir, size, mod); break; + case 73: VG_(transfer) (&s390x->guest_v21, buf, dir, size, mod); break; + case 74: VG_(transfer) (&s390x->guest_v22, buf, dir, size, mod); break; + case 75: VG_(transfer) (&s390x->guest_v23, buf, dir, size, mod); break; + case 76: VG_(transfer) (&s390x->guest_v24, buf, dir, size, mod); break; + case 77: VG_(transfer) (&s390x->guest_v25, buf, dir, size, mod); break; + case 78: VG_(transfer) (&s390x->guest_v26, buf, dir, size, mod); break; + case 79: VG_(transfer) (&s390x->guest_v27, buf, dir, size, mod); break; + case 80: VG_(transfer) (&s390x->guest_v28, buf, dir, size, mod); break; + case 81: VG_(transfer) (&s390x->guest_v29, buf, dir, size, mod); break; + case 82: VG_(transfer) (&s390x->guest_v30, buf, dir, size, mod); break; + case 83: VG_(transfer) (&s390x->guest_v31, buf, dir, size, mod); break; default: vg_assert(0); } } static +Bool have_vx (void) +{ + VexArch va; + VexArchInfo vai; + VG_(machine_get_VexArchInfo) (&va, &vai); + return (vai.hwcaps & VEX_HWCAPS_S390X_VX) != 0; +} + +static const char* target_xml (Bool shadow_mode) { if (shadow_mode) { - return "s390x-generic-valgrind.xml"; + if (have_vx()) + return "s390x-vx-linux-valgrind.xml"; + else + return "s390x-generic-valgrind.xml"; } else { - return "s390x-generic.xml"; - } + if (have_vx()) + return "s390x-vx-linux.xml"; + else + return "s390x-generic.xml"; + } } static CORE_ADDR** target_get_dtv (ThreadState *tst) @@ -206,7 +286,7 @@ static CORE_ADDR** target_get_dtv (ThreadState *tst) } static struct valgrind_target_ops low_target = { - num_regs, + -1, // Override at init time. regs, 17, //sp = r15, which is register offset 17 in regs transfer_register, @@ -220,6 +300,11 @@ static struct valgrind_target_ops low_target = { void s390x_init_architecture (struct valgrind_target_ops *target) { *target = low_target; + if (have_vx()) + num_regs = num_regs_all; + else + num_regs = num_regs_all - 32; // Remove all VX registers. + target->num_regs = num_regs; set_register_cache (regs, num_regs); gdbserver_expedite_regs = expedite_regs; } |
|
From: Andreas A. <ar...@so...> - 2018-11-14 15:29:32
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=71002d8a5111d02ce8049c55017a8d948c820e35 commit 71002d8a5111d02ce8049c55017a8d948c820e35 Author: Andreas Arnez <ar...@li...> Date: Thu Oct 25 13:47:12 2018 +0200 Bug 400490 s390x: Fix register allocation for VRs vs FPRs On s390x, if vector registers are available, they are fed to the register allocator as if they were separate from the floating-point registers. But in fact the FPRs are embedded in the VRs. So for instance, if both f3 and v3 are allocated and used at the same time, corruption will result. This is fixed by offering only the non-overlapping VRs, v16 to v31, to the register allocator instead. Diff: --- NEWS | 1 + VEX/priv/host_s390_defs.c | 17 +++++++---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 987d928..63287bb 100644 --- a/NEWS +++ b/NEWS @@ -47,6 +47,7 @@ where XXXXXX is the bug number as listed below. 399301 Use inlined frames in Massif XTree output. 399322 Improve callgrind_annotate output +400490 s390x: VRs allocated as if separate from FPRs Release 3.14.0 (9 October 2018) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/VEX/priv/host_s390_defs.c b/VEX/priv/host_s390_defs.c index 6c22ac8..98ac938 100644 --- a/VEX/priv/host_s390_defs.c +++ b/VEX/priv/host_s390_defs.c @@ -59,7 +59,6 @@ static UInt s390_tchain_load64_len(void); /* A mapping from register number to register index */ static Int gpr_index[16]; // GPR regno -> register index -static Int fpr_index[16]; // FPR regno -> register index static Int vr_index[32]; // VR regno -> register index HReg @@ -73,7 +72,7 @@ s390_hreg_gpr(UInt regno) HReg s390_hreg_fpr(UInt regno) { - Int ix = fpr_index[regno]; + Int ix = vr_index[regno]; vassert(ix >= 0); return mkHReg(/*virtual*/False, HRcFlt64, regno, ix); } @@ -463,11 +462,9 @@ getRRegUniverse_S390(void) RRegUniverse__init(ru); - /* Assign invalid values to the gpr/fpr/vr_index */ + /* Assign invalid values to the gpr/vr_index */ for (UInt i = 0; i < sizeof gpr_index / sizeof gpr_index[0]; ++i) gpr_index[i] = -1; - for (UInt i = 0; i < sizeof fpr_index / sizeof fpr_index[0]; ++i) - fpr_index[i] = -1; for (UInt i = 0; i < sizeof vr_index / sizeof vr_index[0]; ++i) vr_index[i] = -1; @@ -494,17 +491,17 @@ getRRegUniverse_S390(void) ru->allocable_start[HRcFlt64] = ru->size; for (UInt regno = 8; regno <= 15; ++regno) { - fpr_index[regno] = ru->size; + vr_index[regno] = ru->size; ru->regs[ru->size++] = s390_hreg_fpr(regno); } for (UInt regno = 0; regno <= 7; ++regno) { - fpr_index[regno] = ru->size; + vr_index[regno] = ru->size; ru->regs[ru->size++] = s390_hreg_fpr(regno); } ru->allocable_end[HRcFlt64] = ru->size - 1; ru->allocable_start[HRcVec128] = ru->size; - for (UInt regno = 0; regno <= 31; ++regno) { + for (UInt regno = 16; regno <= 31; ++regno) { vr_index[regno] = ru->size; ru->regs[ru->size++] = s390_hreg_vr(regno); } @@ -527,12 +524,12 @@ getRRegUniverse_S390(void) /* Sanity checking */ for (UInt i = 0; i < sizeof gpr_index / sizeof gpr_index[0]; ++i) vassert(gpr_index[i] >= 0); - for (UInt i = 0; i < sizeof fpr_index / sizeof fpr_index[0]; ++i) - vassert(fpr_index[i] >= 0); for (UInt i = 0; i < sizeof vr_index / sizeof vr_index[0]; ++i) vassert(vr_index[i] >= 0); initialised = True; + + RRegUniverse__check_is_sane(ru); return ru; } |
|
From: Andreas A. <ar...@so...> - 2018-11-14 15:29:31
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=9545e9f96beda6e9f2205bdb3c3e96edaf8d9e2b commit 9545e9f96beda6e9f2205bdb3c3e96edaf8d9e2b Author: Andreas Arnez <ar...@li...> Date: Tue Oct 30 17:06:38 2018 +0100 Bug 400491 s390x: Sign-extend immediate operand of LOCHI and friends The VEX implementation of each of the z/Architecture instructions LOCHI, LOCHHI, and LOCGHI treats the immediate 16-bit operand as an unsigned integer instead of a signed integer. This is fixed. Diff: --- NEWS | 1 + VEX/priv/guest_s390_toIR.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 63287bb..e0917e2 100644 --- a/NEWS +++ b/NEWS @@ -48,6 +48,7 @@ where XXXXXX is the bug number as listed below. 399301 Use inlined frames in Massif XTree output. 399322 Improve callgrind_annotate output 400490 s390x: VRs allocated as if separate from FPRs +400491 s390x: Operand of LOCH treated as unsigned integer Release 3.14.0 (9 October 2018) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/VEX/priv/guest_s390_toIR.c b/VEX/priv/guest_s390_toIR.c index 60b6081..9c4d79b 100644 --- a/VEX/priv/guest_s390_toIR.c +++ b/VEX/priv/guest_s390_toIR.c @@ -16307,7 +16307,7 @@ static const HChar * s390_irgen_LOCHHI(UChar r1, UChar m3, UShort i2, UChar unused) { next_insn_if(binop(Iop_CmpEQ32, s390_call_calculate_cond(m3), mkU32(0))); - put_gpr_w0(r1, mkU32(i2)); + put_gpr_w0(r1, mkU32((UInt)(Int)(Short)i2)); return "lochhi"; } @@ -16316,7 +16316,7 @@ static const HChar * s390_irgen_LOCHI(UChar r1, UChar m3, UShort i2, UChar unused) { next_insn_if(binop(Iop_CmpEQ32, s390_call_calculate_cond(m3), mkU32(0))); - put_gpr_w1(r1, mkU32(i2)); + put_gpr_w1(r1, mkU32((UInt)(Int)(Short)i2)); return "lochi"; } @@ -16325,7 +16325,7 @@ static const HChar * s390_irgen_LOCGHI(UChar r1, UChar m3, UShort i2, UChar unused) { next_insn_if(binop(Iop_CmpEQ32, s390_call_calculate_cond(m3), mkU32(0))); - put_gpr_dw0(r1, mkU64(i2)); + put_gpr_dw0(r1, mkU64((UInt)(Int)(Short)i2)); return "locghi"; } |
|
From: Philippe W. <phi...@so...> - 2018-11-06 21:09:31
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=1d42a625abd8b6d24186e6bda2b401ee24a118c4 commit 1d42a625abd8b6d24186e6bda2b401ee24a118c4 Author: Philippe Waroquiers <phi...@sk...> Date: Tue Nov 6 21:40:43 2018 +0100 Make white space style more consistent, no functional impact. But this time, rather consistently use *no* space between function name and function arg list. Diff: --- coregrind/vgdb.c | 886 +++++++++++++++++++++++++++---------------------------- 1 file changed, 443 insertions(+), 443 deletions(-) diff --git a/coregrind/vgdb.c b/coregrind/vgdb.c index 5ae5e04..075c737 100644 --- a/coregrind/vgdb.c +++ b/coregrind/vgdb.c @@ -87,29 +87,29 @@ VgdbShared64 *shared64; #define VS_vgdb_pid (shared32 != NULL ? shared32->vgdb_pid : shared64->vgdb_pid) -void *vmalloc (size_t size) +void *vmalloc(size_t size) { - void * mem = malloc (size); + void * mem = malloc(size); if (mem == NULL) - XERROR (errno, "can't allocate memory\n"); + XERROR(errno, "can't allocate memory\n"); return mem; } -void *vrealloc (void *ptr,size_t size) +void *vrealloc(void *ptr,size_t size) { - void * mem = realloc (ptr, size); + void * mem = realloc(ptr, size); if (mem == NULL) - XERROR (errno, "can't reallocate memory\n"); + XERROR(errno, "can't reallocate memory\n"); return mem; } /* Return the name of a directory for temporary files. */ static -const char *vgdb_tmpdir (void) +const char *vgdb_tmpdir(void) { const char *tmpdir; - tmpdir = getenv ("TMPDIR"); + tmpdir = getenv("TMPDIR"); if (tmpdir == NULL || *tmpdir == '\0') tmpdir = VG_TMPDIR; if (tmpdir == NULL || *tmpdir == '\0') @@ -121,81 +121,81 @@ const char *vgdb_tmpdir (void) /* Return the default path prefix for the named pipes (FIFOs) used by vgdb/gdb to communicate with valgrind */ static -char *vgdb_prefix_default (void) +char *vgdb_prefix_default(void) { static HChar *prefix; if (prefix == NULL) { - const char *tmpdir = vgdb_tmpdir (); - prefix = vmalloc (strlen (tmpdir) + strlen ("/vgdb-pipe") + 1); - strcpy (prefix, tmpdir); - strcat (prefix, "/vgdb-pipe"); + const char *tmpdir = vgdb_tmpdir(); + prefix = vmalloc(strlen(tmpdir) + strlen("/vgdb-pipe") + 1); + strcpy(prefix, tmpdir); + strcat(prefix, "/vgdb-pipe"); } return prefix; } /* add nrw to the written_by_vgdb field of shared32 or shared64 */ static -void add_written (int nrw) +void add_written(int nrw) { if (shared32 != NULL) shared32->written_by_vgdb += nrw; else if (shared64 != NULL) shared64->written_by_vgdb += nrw; else - assert (0); + assert(0); } static int shared_mem_fd = -1; static -void map_vgdbshared (char* shared_mem) +void map_vgdbshared(char* shared_mem) { struct stat fdstat; void **s; - shared_mem_fd = open (shared_mem, O_RDWR); + shared_mem_fd = open(shared_mem, O_RDWR); /* shared_mem_fd will not be closed till vgdb exits. */ if (shared_mem_fd == -1) - XERROR (errno, "error opening %s shared memory file\n", shared_mem); + XERROR(errno, "error opening %s shared memory file\n", shared_mem); - if (fstat (shared_mem_fd, &fdstat) != 0) - XERROR (errno, "fstat"); + if (fstat(shared_mem_fd, &fdstat) != 0) + XERROR(errno, "fstat"); - if (fdstat.st_size == sizeof (VgdbShared64)) + if (fdstat.st_size == sizeof(VgdbShared64)) s = (void*) &shared64; - else if (fdstat.st_size == sizeof (VgdbShared32)) + else if (fdstat.st_size == sizeof(VgdbShared32)) s = (void*) &shared32; else #if VEX_HOST_WORDSIZE == 8 - XERROR (0, - "error size shared memory file %s.\n" - "expecting size %d (64bits) or %d (32bits) got %ld.\n", - shared_mem, - (int) sizeof (VgdbShared64), (int) sizeof (VgdbShared32), - (long int)fdstat.st_size); + XERROR(0, + "error size shared memory file %s.\n" + "expecting size %d (64bits) or %d (32bits) got %ld.\n", + shared_mem, + (int) sizeof(VgdbShared64), (int) sizeof(VgdbShared32), + (long int)fdstat.st_size); #elif VEX_HOST_WORDSIZE == 4 - XERROR (0, - "error size shared memory file %s.\n" - "expecting size %d (32bits) got %ld.\n", - shared_mem, - (int) sizeof (VgdbShared32), - fdstat.st_size); + XERROR(0, + "error size shared memory file %s.\n" + "expecting size %d (32bits) got %ld.\n", + shared_mem, + (int) sizeof(VgdbShared32), + fdstat.st_size); #else # error "unexpected wordsize" #endif #if VEX_HOST_WORDSIZE == 4 if (shared64 != NULL) - XERROR (0, "cannot use 32 bits vgdb with a 64bits valgrind process\n"); + XERROR(0, "cannot use 32 bits vgdb with a 64bits valgrind process\n"); /* But we can use a 64 bits vgdb with a 32 bits valgrind */ #endif - *s = (void*) mmap (NULL, fdstat.st_size, - PROT_READ|PROT_WRITE, MAP_SHARED, - shared_mem_fd, 0); + *s = (void*) mmap(NULL, fdstat.st_size, + PROT_READ|PROT_WRITE, MAP_SHARED, + shared_mem_fd, 0); if (*s == (void *) -1) - XERROR (errno, "error mmap shared memory file %s\n", shared_mem); + XERROR(errno, "error mmap shared memory file %s\n", shared_mem); } @@ -208,7 +208,7 @@ static int max_invoke_ms = 100; #define NEVER 99999999 static int cmd_time_out = NEVER; static -void *invoke_gdbserver_in_valgrind (void *v_pid) +void *invoke_gdbserver_in_valgrind(void *v_pid) { struct timeval cmd_max_end_time; Bool cmd_started = False; @@ -221,28 +221,28 @@ void *invoke_gdbserver_in_valgrind (void *v_pid) int invoked_written = -1; unsigned int usecs; - pthread_cleanup_push (invoker_cleanup_restore_and_detach, v_pid); + pthread_cleanup_push(invoker_cleanup_restore_and_detach, v_pid); while (!shutting_down) { written_by_vgdb_before_sleep = VS_written_by_vgdb; seen_by_valgrind_before_sleep = VS_seen_by_valgrind; - DEBUG (3, - "written_by_vgdb_before_sleep %d " - "seen_by_valgrind_before_sleep %d\n", - written_by_vgdb_before_sleep, - seen_by_valgrind_before_sleep); + DEBUG(3, + "written_by_vgdb_before_sleep %d " + "seen_by_valgrind_before_sleep %d\n", + written_by_vgdb_before_sleep, + seen_by_valgrind_before_sleep); if (cmd_time_out != NEVER && !cmd_started && written_by_vgdb_before_sleep > seen_by_valgrind_before_sleep) { /* A command was started. Record the time at which it was started. */ - DEBUG (1, "IO for command started\n"); - gettimeofday (&cmd_max_end_time, NULL); + DEBUG(1, "IO for command started\n"); + gettimeofday(&cmd_max_end_time, NULL); cmd_max_end_time.tv_sec += cmd_time_out; cmd_started = True; } if (max_invoke_ms > 0) { usecs = 1000 * max_invoke_ms; - gettimeofday (&invoke_time, NULL); + gettimeofday(&invoke_time, NULL); invoke_time.tv_sec += max_invoke_ms / 1000; invoke_time.tv_usec += 1000 * (max_invoke_ms % 1000); invoke_time.tv_sec += invoke_time.tv_usec / (1000 * 1000); @@ -257,7 +257,7 @@ void *invoke_gdbserver_in_valgrind (void *v_pid) if (usecs == 0 || usecs > 1000 * 1000) usecs = 1000 * 1000; } - usleep (usecs); + usleep(usecs); /* If nothing happened during our sleep, let's try to wake up valgrind or check for cmd time out. */ @@ -265,31 +265,31 @@ void *invoke_gdbserver_in_valgrind (void *v_pid) && seen_by_valgrind_before_sleep == VS_seen_by_valgrind && VS_written_by_vgdb > VS_seen_by_valgrind) { struct timeval now; - gettimeofday (&now, NULL); - DEBUG (2, - "after sleep " - "written_by_vgdb %d " - "seen_by_valgrind %d " - "invoked_written %d\n", - VS_written_by_vgdb, - VS_seen_by_valgrind, - invoked_written); + gettimeofday(&now, NULL); + DEBUG(2, + "after sleep " + "written_by_vgdb %d " + "seen_by_valgrind %d " + "invoked_written %d\n", + VS_written_by_vgdb, + VS_seen_by_valgrind, + invoked_written); /* if the pid does not exist anymore, we better stop */ - if (kill (pid, 0) != 0) - XERROR (errno, - "invoke_gdbserver_in_valgrind: " - "check for pid %d existence failed\n", pid); + if (kill(pid, 0) != 0) + XERROR(errno, + "invoke_gdbserver_in_valgrind: " + "check for pid %d existence failed\n", pid); if (cmd_started) { - if (timercmp (&now, &cmd_max_end_time, >)) - XERROR (0, - "pid %d did not handle a command in %d seconds\n", - pid, cmd_time_out); + if (timercmp(&now, &cmd_max_end_time, >)) + XERROR(0, + "pid %d did not handle a command in %d seconds\n", + pid, cmd_time_out); } if (max_invoke_ms > 0 && timercmp (&now, &invoke_time, >=)) { /* only need to wake up if the nr written has changed since last invoke. */ if (invoked_written != written_by_vgdb_before_sleep) { - if (invoker_invoke_gdbserver (pid)) { + if (invoker_invoke_gdbserver(pid)) { /* If invoke successful, no need to invoke again for the same value of written_by_vgdb_before_sleep. */ invoked_written = written_by_vgdb_before_sleep; @@ -299,25 +299,25 @@ void *invoke_gdbserver_in_valgrind (void *v_pid) } else { // Something happened => restart timer check. if (cmd_time_out != NEVER) { - DEBUG (2, "some IO was done => restart command\n"); + DEBUG(2, "some IO was done => restart command\n"); cmd_started = False; } } } - pthread_cleanup_pop (0); + pthread_cleanup_pop(0); return NULL; } static -int open_fifo (const char* name, int flags, const char* desc) +int open_fifo(const char* name, int flags, const char* desc) { int fd; - DEBUG (1, "opening %s %s\n", name, desc); - fd = open (name, flags); + DEBUG(1, "opening %s %s\n", name, desc); + fd = open(name, flags); if (fd == -1) - XERROR (errno, "error opening %s %s\n", name, desc); + XERROR(errno, "error opening %s %s\n", name, desc); - DEBUG (1, "opened %s %s fd %d\n", name, desc, fd); + DEBUG(1, "opened %s %s fd %d\n", name, desc, fd); return fd; } @@ -326,33 +326,33 @@ int open_fifo (const char* name, int flags, const char* desc) This allows to avoid having two vgdb speaking with the same Valgrind gdbserver as this causes serious headaches to the protocol. */ static -void acquire_lock (int fd, int valgrind_pid) +void acquire_lock(int fd, int valgrind_pid) { struct flock fl; fl.l_type = F_WRLCK; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 1; - if (fcntl (fd, F_SETLK, &fl) < 0) { + if (fcntl(fd, F_SETLK, &fl) < 0) { if (errno == EAGAIN || errno == EACCES) { - XERROR (errno, - "Cannot acquire lock.\n" - "Probably vgdb pid %d already speaks with Valgrind pid %d\n", - VS_vgdb_pid, - valgrind_pid); + XERROR(errno, + "Cannot acquire lock.\n" + "Probably vgdb pid %d already speaks with Valgrind pid %d\n", + VS_vgdb_pid, + valgrind_pid); } else { - XERROR (errno, "cannot acquire lock.\n"); + XERROR(errno, "cannot acquire lock.\n"); } } /* Here, we have the lock. It will be released when fd will be closed. */ /* We indicate our pid to Valgrind gdbserver */ if (shared32 != NULL) - shared32->vgdb_pid = getpid (); + shared32->vgdb_pid = getpid(); else if (shared64 != NULL) - shared64->vgdb_pid = getpid (); + shared64->vgdb_pid = getpid(); else - assert (0); + assert(0); } #define PBUFSIZ 16384 /* keep in sync with server.h */ @@ -361,17 +361,17 @@ void acquire_lock (int fd, int valgrind_pid) Returns the nr of characters read, -1 if error. desc is a string used in tracing */ static -int read_buf (int fd, char* buf, const char* desc) +int read_buf(int fd, char* buf, const char* desc) { int nrread; - DEBUG (2, "reading %s\n", desc); - nrread = read (fd, buf, PBUFSIZ); + DEBUG(2, "reading %s\n", desc); + nrread = read(fd, buf, PBUFSIZ); if (nrread == -1) { - ERROR (errno, "error reading %s\n", desc); + ERROR(errno, "error reading %s\n", desc); return -1; } buf[nrread] = '\0'; - DEBUG (2, "read %s %s\n", desc, buf); + DEBUG(2, "read %s %s\n", desc, buf); return nrread; } @@ -381,22 +381,22 @@ int read_buf (int fd, char* buf, const char* desc) valgrind process that there is new data. Returns True if write is ok, False if there was a problem. */ static -Bool write_buf (int fd, const char* buf, int size, const char* desc, Bool notify) +Bool write_buf(int fd, const char* buf, int size, const char* desc, Bool notify) { int nrwritten; int nrw; - DEBUG (2, "writing %s len %d %.*s notify: %d\n", desc, size, - size, buf, notify); + DEBUG(2, "writing %s len %d %.*s notify: %d\n", desc, size, + size, buf, notify); nrwritten = 0; while (nrwritten < size) { - nrw = write (fd, buf+nrwritten, size - nrwritten); + nrw = write(fd, buf+nrwritten, size - nrwritten); if (nrw == -1) { - ERROR (errno, "error write %s\n", desc); + ERROR(errno, "error write %s\n", desc); return False; } nrwritten = nrwritten + nrw; if (notify) - add_written (nrw); + add_written(nrw); } return True; } @@ -408,7 +408,7 @@ typedef enum { TO_PID } ConnectionKind; static const int NumConnectionKind = TO_PID+1; static -const char *ppConnectionKind (ConnectionKind con) +const char *ppConnectionKind(ConnectionKind con) { switch (con) { case FROM_GDB: return "FROM_GDB"; @@ -427,22 +427,22 @@ static char *from_gdb_to_pid; /* fifo name to write gdb command to pid */ Returns False in case of error. to_pid is the file descriptor to write to the process pid. */ static -Bool read_from_gdb_write_to_pid (int to_pid) +Bool read_from_gdb_write_to_pid(int to_pid) { char buf[PBUFSIZ+1]; // +1 for trailing \0 int nrread; - nrread = read_buf (from_gdb, buf, "from gdb on stdin"); + nrread = read_buf(from_gdb, buf, "from gdb on stdin"); if (nrread <= 0) { if (nrread == 0) - DEBUG (1, "read 0 bytes from gdb => assume exit\n"); + DEBUG(1, "read 0 bytes from gdb => assume exit\n"); else - DEBUG (1, "error reading bytes from gdb\n"); - close (from_gdb); + DEBUG(1, "error reading bytes from gdb\n"); + close(from_gdb); shutting_down = True; return False; } - return write_buf (to_pid, buf, nrread, "to_pid", /* notify */ True); + return write_buf(to_pid, buf, nrread, "to_pid", /* notify */ True); } static int to_gdb = 1; /* stdout by default, changed if --port is given. */ @@ -451,114 +451,114 @@ static char *to_gdb_from_pid; /* fifo name to read pid replies */ Returns False in case of error. from_pid is the file descriptor to read data from the process pid. */ static -Bool read_from_pid_write_to_gdb (int from_pid) +Bool read_from_pid_write_to_gdb(int from_pid) { char buf[PBUFSIZ+1]; // +1 for trailing \0 int nrread; - nrread = read_buf (from_pid, buf, "from pid"); + nrread = read_buf(from_pid, buf, "from pid"); if (nrread <= 0) { if (nrread == 0) - DEBUG (1, "read 0 bytes from pid => assume exit\n"); + DEBUG(1, "read 0 bytes from pid => assume exit\n"); else - DEBUG (1, "error reading bytes from pid\n"); - close (from_pid); + DEBUG(1, "error reading bytes from pid\n"); + close(from_pid); shutting_down = True; return False; } - return write_buf (to_gdb, buf, nrread, "to_gdb", /* notify */ False); + return write_buf(to_gdb, buf, nrread, "to_gdb", /* notify */ False); } static -void wait_for_gdb_connect (int in_port) +void wait_for_gdb_connect(int in_port) { struct sockaddr_in addr; - int listen_gdb = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP); + int listen_gdb = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); int gdb_connect; if (-1 == listen_gdb) { - XERROR (errno, "cannot create socket"); + XERROR(errno, "cannot create socket"); } - memset (&addr, 0, sizeof(addr)); + memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; - addr.sin_port = htons ((unsigned short int)in_port); + addr.sin_port = htons((unsigned short int)in_port); addr.sin_addr.s_addr = INADDR_ANY; - if (-1 == bind (listen_gdb, (struct sockaddr *)&addr, sizeof(addr))) { - XERROR (errno, "bind failed"); + if (-1 == bind(listen_gdb, (struct sockaddr *)&addr, sizeof(addr))) { + XERROR(errno, "bind failed"); } - fprintf (stderr, "listening on port %d ...", in_port); - fflush (stderr); - if (-1 == listen (listen_gdb, 1)) { - XERROR (errno, "error listen failed"); + fprintf(stderr, "listening on port %d ...", in_port); + fflush(stderr); + if (-1 == listen(listen_gdb, 1)) { + XERROR(errno, "error listen failed"); } - gdb_connect = accept (listen_gdb, NULL, NULL); + gdb_connect = accept(listen_gdb, NULL, NULL); if (gdb_connect < 0) { - XERROR (errno, "accept failed"); + XERROR(errno, "accept failed"); } - fprintf (stderr, "connected.\n"); - fflush (stderr); - close (listen_gdb); + fprintf(stderr, "connected.\n"); + fflush(stderr); + close(listen_gdb); from_gdb = gdb_connect; to_gdb = gdb_connect; } /* prepares the FIFOs filenames, map the shared memory. */ static -void prepare_fifos_and_shared_mem (int pid) +void prepare_fifos_and_shared_mem(int pid) { const HChar *user, *host; unsigned len; - user = getenv ("LOGNAME"); - if (user == NULL) user = getenv ("USER"); + user = getenv("LOGNAME"); + if (user == NULL) user = getenv("USER"); if (user == NULL) user = "???"; - if (strchr (user, '/')) user = "???"; + if (strchr(user, '/')) user = "???"; - host = getenv ("HOST"); - if (host == NULL) host = getenv ("HOSTNAME"); + host = getenv("HOST"); + if (host == NULL) host = getenv("HOSTNAME"); if (host == NULL) host = "???"; - if (strchr (host, '/')) host = "???"; + if (strchr(host, '/')) host = "???"; - len = strlen (vgdb_prefix) + strlen (user) + strlen (host) + 40; - from_gdb_to_pid = vmalloc (len); - to_gdb_from_pid = vmalloc (len); - shared_mem = vmalloc (len); + len = strlen(vgdb_prefix) + strlen(user) + strlen(host) + 40; + from_gdb_to_pid = vmalloc(len); + to_gdb_from_pid = vmalloc(len); + shared_mem = vmalloc(len); /* below 3 lines must match the equivalent in remote-utils.c */ - sprintf (from_gdb_to_pid, "%s-from-vgdb-to-%d-by-%s-on-%s", vgdb_prefix, - pid, user, host); - sprintf (to_gdb_from_pid, "%s-to-vgdb-from-%d-by-%s-on-%s", vgdb_prefix, - pid, user, host); - sprintf (shared_mem, "%s-shared-mem-vgdb-%d-by-%s-on-%s", vgdb_prefix, - pid, user, host); - DEBUG (1, "vgdb: using %s %s %s\n", - from_gdb_to_pid, to_gdb_from_pid, shared_mem); - - map_vgdbshared (shared_mem); + sprintf(from_gdb_to_pid, "%s-from-vgdb-to-%d-by-%s-on-%s", vgdb_prefix, + pid, user, host); + sprintf(to_gdb_from_pid, "%s-to-vgdb-from-%d-by-%s-on-%s", vgdb_prefix, + pid, user, host); + sprintf(shared_mem, "%s-shared-mem-vgdb-%d-by-%s-on-%s", vgdb_prefix, + pid, user, host); + DEBUG(1, "vgdb: using %s %s %s\n", + from_gdb_to_pid, to_gdb_from_pid, shared_mem); + + map_vgdbshared(shared_mem); } /* Convert hex digit A to a number. */ static int -fromhex (int a) +fromhex(int a) { if (a >= '0' && a <= '9') return a - '0'; else if (a >= 'a' && a <= 'f') return a - 'a' + 10; else - XERROR (0, "Reply contains invalid hex digit %c\n", a); + XERROR(0, "Reply contains invalid hex digit %c\n", a); return 0; } /* Returns next char from fd. -1 if error, -2 if EOF. NB: must always call it with the same fd */ static int -readchar (int fd) +readchar(int fd) { static char buf[PBUFSIZ+1]; // +1 for trailing \0 static int bufcnt = 0; @@ -568,14 +568,14 @@ readchar (int fd) if (bufcnt-- > 0) return *bufp++; - bufcnt = read_buf (fd, buf, "static buf readchar"); + bufcnt = read_buf(fd, buf, "static buf readchar"); if (bufcnt <= 0) { if (bufcnt == 0) { - fprintf (stderr, "readchar: Got EOF\n"); + fprintf(stderr, "readchar: Got EOF\n"); return -2; } else { - ERROR (errno, "readchar\n"); + ERROR(errno, "readchar\n"); return -1; } } @@ -590,7 +590,7 @@ readchar (int fd) If checksum incorrect, writes a - on ackfd. Returns length of packet, or -1 if error or -2 if EOF. */ static int -getpkt (char *buf, int fromfd, int ackfd) +getpkt(char *buf, int fromfd, int ackfd) { char *bp; unsigned char csum, c1, c2; @@ -600,17 +600,17 @@ getpkt (char *buf, int fromfd, int ackfd) csum = 0; while (1) { - c = readchar (fromfd); + c = readchar(fromfd); if (c == '$') break; - DEBUG (2, "[getpkt: discarding char '%c']\n", c); + DEBUG(2, "[getpkt: discarding char '%c']\n", c); if (c < 0) return c; } bp = buf; while (1) { - c = readchar (fromfd); + c = readchar(fromfd); if (c < 0) return c; if (c == '#') @@ -621,7 +621,7 @@ getpkt (char *buf, int fromfd, int ackfd) int prev; prev = *(bp-1); csum += c; - repeat = readchar (fromfd); + repeat = readchar(fromfd); csum += repeat; for (r = 0; r < repeat - 29; r ++) *bp++ = prev; @@ -632,21 +632,21 @@ getpkt (char *buf, int fromfd, int ackfd) } *bp = 0; - c1 = fromhex (readchar (fromfd)); - c2 = fromhex (readchar (fromfd)); + c1 = fromhex(readchar (fromfd)); + c2 = fromhex(readchar (fromfd)); if (csum == (c1 << 4) + c2) break; - fprintf (stderr, "Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n", - (c1 << 4) + c2, csum, buf); - if (write (ackfd, "-", 1) != 1) - ERROR (0, "error when writing - (nack)\n"); + fprintf(stderr, "Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n", + (c1 << 4) + c2, csum, buf); + if (write(ackfd, "-", 1) != 1) + ERROR(0, "error when writing - (nack)\n"); else - add_written (1); + add_written(1); } - DEBUG (2, "getpkt (\"%s\"); [no ack] \n", buf); + DEBUG(2, "getpkt (\"%s\"); [no ack] \n", buf); return bp - buf; } @@ -660,7 +660,7 @@ static int sigusr1_fd = -1; static pthread_t invoke_gdbserver_in_valgrind_thread; static -void received_signal (int signum) +void received_signal(int signum) { if (signum == SIGINT) sigint++; @@ -668,8 +668,8 @@ void received_signal (int signum) sigusr1++; if (sigusr1_fd >= 0) { char control_c = '\003'; - write_buf (sigusr1_fd, &control_c, 1, - "write \\003 on SIGUSR1", /* notify */ True); + write_buf(sigusr1_fd, &control_c, 1, + "write \\003 on SIGUSR1", /* notify */ True); } } else if (signum == SIGTERM) { @@ -682,43 +682,43 @@ void received_signal (int signum) sigpipe++; } else if (signum == SIGALRM) { sigalrm++; -#if defined (VGPV_arm_linux_android) \ - || defined (VGPV_x86_linux_android) \ - || defined (VGPV_mips32_linux_android) \ - || defined (VGPV_arm64_linux_android) +#if defined(VGPV_arm_linux_android) \ + || defined(VGPV_x86_linux_android) \ + || defined(VGPV_mips32_linux_android) \ + || defined(VGPV_arm64_linux_android) /* Android has no pthread_cancel. As it also does not have an invoker implementation, there is no need for cleanup action. So, we just do nothing. */ - DEBUG (1, "sigalrm received, no action on android\n"); + DEBUG(1, "sigalrm received, no action on android\n"); #else /* Note: we cannot directly invoke restore_and_detach : this must be done by the thread that has attached. We have in this thread pushed a cleanup handler that will cleanup what is needed. */ - DEBUG (1, "pthread_cancel invoke_gdbserver_in_valgrind_thread\n"); - pthread_cancel (invoke_gdbserver_in_valgrind_thread); + DEBUG(1, "pthread_cancel invoke_gdbserver_in_valgrind_thread\n"); + pthread_cancel(invoke_gdbserver_in_valgrind_thread); #endif } else { - ERROR (0, "unexpected signal %d\n", signum); + ERROR(0, "unexpected signal %d\n", signum); } } /* install the signal handlers allowing e.g. vgdb to cleanup in case of termination. */ static -void install_handlers (void) +void install_handlers(void) { struct sigaction action, oldaction; action.sa_handler = received_signal; - sigemptyset (&action.sa_mask); + sigemptyset(&action.sa_mask); action.sa_flags = 0; /* SIGINT: when user types C-c in gdb, this sends a SIGINT to vgdb + causes a character to be sent to remote gdbserver. The later is enough to wakeup the valgrind process. */ - if (sigaction (SIGINT, &action, &oldaction) != 0) - XERROR (errno, "vgdb error sigaction SIGINT\n"); + if (sigaction(SIGINT, &action, &oldaction) != 0) + XERROR(errno, "vgdb error sigaction SIGINT\n"); /* We might do something more intelligent than just reporting this SIGINT E.g. behave similarly to the gdb: two control-C without feedback from the debugged process would @@ -726,39 +726,39 @@ void install_handlers (void) /* SIGUSR1: this is used to facilitate automatic testing. When vgdb receives this signal, it will simulate the user typing C-c. */ - if (sigaction (SIGUSR1, &action, &oldaction) != 0) - XERROR (errno, "vgdb error sigaction SIGUSR1\n"); + if (sigaction(SIGUSR1, &action, &oldaction) != 0) + XERROR(errno, "vgdb error sigaction SIGUSR1\n"); /* SIGTERM: can receive this signal (e.g. from gdb) to terminate vgdb when detaching or similar. A clean shutdown will be done as both the read and write side will detect an end of file. */ - if (sigaction (SIGTERM, &action, &oldaction) != 0) - XERROR (errno, "vgdb error sigaction SIGTERM\n"); + if (sigaction(SIGTERM, &action, &oldaction) != 0) + XERROR(errno, "vgdb error sigaction SIGTERM\n"); /* SIGPIPE: can receive this signal when gdb detaches or kill the process debugged: gdb will close its pipes to vgdb. vgdb must resist to this signal to allow a clean shutdown. */ - if (sigaction (SIGPIPE, &action, &oldaction) != 0) - XERROR (errno, "vgdb error sigaction SIGPIPE\n"); + if (sigaction(SIGPIPE, &action, &oldaction) != 0) + XERROR(errno, "vgdb error sigaction SIGPIPE\n"); /* SIGALRM: in case invoke thread is blocked, alarm is used to cleanup. */ - if (sigaction (SIGALRM, &action, &oldaction) != 0) - XERROR (errno, "vgdb error sigaction SIGALRM\n"); + if (sigaction(SIGALRM, &action, &oldaction) != 0) + XERROR(errno, "vgdb error sigaction SIGALRM\n"); /* unmask all signals, in case the process that launched vgdb masked some. */ - if (sigprocmask (SIG_SETMASK, &action.sa_mask, NULL) != 0) - XERROR (errno, "vgdb error sigprocmask"); + if (sigprocmask(SIG_SETMASK, &action.sa_mask, NULL) != 0) + XERROR(errno, "vgdb error sigprocmask"); } /* close the FIFOs provided connections, terminate the invoker thread. */ static -void close_connection (int to_pid, int from_pid) +void close_connection(int to_pid, int from_pid) { - DEBUG (1, "nr received signals: sigint %d sigterm %d sighup %d sigpipe %d\n", - sigint, sigterm, sighup, sigpipe); + DEBUG(1, "nr received signals: sigint %d sigterm %d sighup %d sigpipe %d\n", + sigint, sigterm, sighup, sigpipe); /* Note that we do not forward sigterm to the valgrind process: a sigterm signal is (probably) received from gdb if the user wants to kill the debugged process. The kill instruction has been given to @@ -768,8 +768,8 @@ void close_connection (int to_pid, int from_pid) terminates its gdbserver work. We keep the from pid fifo opened till the invoker thread is finished. This allows the gdbserver to finish sending its last reply. */ - if (close (to_pid) != 0) - ERROR (errno, "close to_pid\n"); + if (close(to_pid) != 0) + ERROR(errno, "close to_pid\n"); /* if there is a task that was busy trying to wake up valgrind process, we wait for it to be terminated otherwise threads @@ -802,39 +802,39 @@ void close_connection (int to_pid, int from_pid) normal case, the gdbserver code in valgrind process must have returned the control in less than the alarm nr of seconds, otherwise, valgrind will stop abnormally with SIGSTOP. */ - (void) alarm (3); + (void) alarm(3); - DEBUG (1, "joining with invoke_gdbserver_in_valgrind_thread\n"); - join = pthread_join (invoke_gdbserver_in_valgrind_thread, NULL); + DEBUG(1, "joining with invoke_gdbserver_in_valgrind_thread\n"); + join = pthread_join(invoke_gdbserver_in_valgrind_thread, NULL); if (join != 0) XERROR (join, "vgdb error pthread_join invoke_gdbserver_in_valgrind_thread\n"); } - if (close (from_pid) != 0) - ERROR (errno, "close from_pid\n"); + if (close(from_pid) != 0) + ERROR(errno, "close from_pid\n"); } /* Relay data between gdb and Valgrind gdbserver, till EOF or an error is encountered. */ static -void gdb_relay (int pid) +void gdb_relay(int pid) { int from_pid = -1; /* fd to read from pid */ int to_pid = -1; /* fd to write to pid */ int shutdown_loop = 0; - fprintf (stderr, "relaying data between gdb and process %d\n", pid); - fflush (stderr); + fprintf(stderr, "relaying data between gdb and process %d\n", pid); + fflush(stderr); if (max_invoke_ms > 0) - pthread_create (&invoke_gdbserver_in_valgrind_thread, NULL, - invoke_gdbserver_in_valgrind, (void *) &pid); - to_pid = open_fifo (from_gdb_to_pid, O_WRONLY, "write to pid"); - acquire_lock (shared_mem_fd, pid); + pthread_create(&invoke_gdbserver_in_valgrind_thread, NULL, + invoke_gdbserver_in_valgrind, (void *) &pid); + to_pid = open_fifo(from_gdb_to_pid, O_WRONLY, "write to pid"); + acquire_lock(shared_mem_fd, pid); - from_pid = open_fifo (to_gdb_from_pid, O_RDONLY|O_NONBLOCK, - "read mode from pid"); + from_pid = open_fifo(to_gdb_from_pid, O_RDONLY|O_NONBLOCK, + "read mode from pid"); sigusr1_fd = to_pid; /* allow simulating user typing control-c */ @@ -859,16 +859,16 @@ void gdb_relay (int pid) pollfds[TO_PID].events = 0; pollfds[TO_PID].revents = 0; - ret = poll (pollfds, - NumConnectionKind, - (shutting_down ? - 1 /* one second */ - : -1 /* infinite */)); - DEBUG (2, "poll ret %d errno %d\n", ret, errno); + ret = poll(pollfds, + NumConnectionKind, + (shutting_down ? + 1 /* one second */ + : -1 /* infinite */)); + DEBUG(2, "poll ret %d errno %d\n", ret, errno); /* check for unexpected error */ if (ret <= 0 && errno != EINTR) { - ERROR (errno, "unexpected poll ret %d\n", ret); + ERROR(errno, "unexpected poll ret %d\n", ret); shutting_down = True; break; } @@ -878,15 +878,15 @@ void gdb_relay (int pid) if (pollfds[ck].revents & POLLIN) { switch (ck) { case FROM_GDB: - if (!read_from_gdb_write_to_pid (to_pid)) + if (!read_from_gdb_write_to_pid(to_pid)) shutting_down = True; break; case FROM_PID: - if (!read_from_pid_write_to_gdb (from_pid)) + if (!read_from_pid_write_to_gdb(from_pid)) shutting_down = True; break; - default: XERROR (0, "unexpected POLLIN on %s\n", - ppConnectionKind (ck)); + default: XERROR(0, "unexpected POLLIN on %s\n", + ppConnectionKind(ck)); } } } @@ -894,21 +894,21 @@ void gdb_relay (int pid) /* check for an fd being in error condition */ for (ck = 0; ck < NumConnectionKind; ck ++) { if (pollfds[ck].revents & POLLERR) { - DEBUG (1, "connection %s fd %d POLLERR error condition\n", - ppConnectionKind (ck), pollfds[ck].fd); - invoker_valgrind_dying (); + DEBUG(1, "connection %s fd %d POLLERR error condition\n", + ppConnectionKind(ck), pollfds[ck].fd); + invoker_valgrind_dying(); shutting_down = True; } if (pollfds[ck].revents & POLLHUP) { - DEBUG (1, "connection %s fd %d POLLHUP error condition\n", - ppConnectionKind (ck), pollfds[ck].fd); - invoker_valgrind_dying (); + DEBUG(1, "connection %s fd %d POLLHUP error condition\n", + ppConnectionKind(ck), pollfds[ck].fd); + invoker_valgrind_dying(); shutting_down = True; } if (pollfds[ck].revents & POLLNVAL) { - DEBUG (1, "connection %s fd %d POLLNVAL error condition\n", - ppConnectionKind (ck), pollfds[ck].fd); - invoker_valgrind_dying (); + DEBUG(1, "connection %s fd %d POLLNVAL error condition\n", + ppConnectionKind(ck), pollfds[ck].fd); + invoker_valgrind_dying(); shutting_down = True; } } @@ -920,22 +920,22 @@ void gdb_relay (int pid) break; } } - close_connection (to_pid, from_pid); + close_connection(to_pid, from_pid); } -static int packet_len_for_command (char *cmd) +static int packet_len_for_command(char *cmd) { /* cmd will be send as a packet $qRcmd,xxxx....................xx#cc */ - return 7+ 2*strlen (cmd) +3 + 1; + return 7+ 2*strlen(cmd) +3 + 1; } /* hyper-minimal protocol implementation that sends the provided commands (using qRcmd packets) and read and display their replies. */ static -void standalone_send_commands (int pid, - int last_command, - char *commands[] ) +void standalone_send_commands(int pid, + int last_command, + char *commands[] ) { int from_pid = -1; /* fd to read from pid */ int to_pid = -1; /* fd to write to pid */ @@ -951,11 +951,11 @@ void standalone_send_commands (int pid, if (max_invoke_ms > 0 || cmd_time_out != NEVER) - pthread_create (&invoke_gdbserver_in_valgrind_thread, NULL, - invoke_gdbserver_in_valgrind, (void *) &pid); + pthread_create(&invoke_gdbserver_in_valgrind_thread, NULL, + invoke_gdbserver_in_valgrind, (void *) &pid); - to_pid = open_fifo (from_gdb_to_pid, O_WRONLY, "write to pid"); - acquire_lock (shared_mem_fd, pid); + to_pid = open_fifo(from_gdb_to_pid, O_WRONLY, "write to pid"); + acquire_lock(shared_mem_fd, pid); /* first send a C-c \003 to pid, so that it wakes up the process After that, we can open the fifo from the pid in read mode @@ -963,108 +963,108 @@ void standalone_send_commands (int pid, At that point, we send our command and expect replies */ buf[0] = '\003'; i = 0; - while (!write_buf (to_pid, buf, 1, - "write \\003 to wake up", /* notify */ True)) { + while (!write_buf(to_pid, buf, 1, + "write \\003 to wake up", /* notify */ True)) { /* If write fails, retries up to 10 times every 0.5 seconds This aims at solving the race condition described in remote-utils.c remote_finish function. */ - usleep (500 * 1000); + usleep(500*1000); i++; if (i >= 10) - XERROR (errno, "failed to send wake up char after 10 trials\n"); + XERROR(errno, "failed to send wake up char after 10 trials\n"); } - from_pid = open_fifo (to_gdb_from_pid, O_RDONLY, - "read cmd result from pid"); + from_pid = open_fifo(to_gdb_from_pid, O_RDONLY, + "read cmd result from pid"); /* Enable no ack mode. */ - write_buf (to_pid, "$QStartNoAckMode#b0", 19, "write start no ack mode", - /* notify */ True); - buflen = getpkt (buf, from_pid, to_pid); - if (buflen != 2 || strcmp (buf, "OK") != 0) { + write_buf(to_pid, "$QStartNoAckMode#b0", 19, "write start no ack mode", + /* notify */ True); + buflen = getpkt(buf, from_pid, to_pid); + if (buflen != 2 || strcmp(buf, "OK") != 0) { if (buflen != 2) - ERROR (0, "no ack mode: unexpected buflen %d\n", buflen); + ERROR(0, "no ack mode: unexpected buflen %d\n", buflen); else - ERROR (0, "no ack mode: unexpected packet %s\n", buf); + ERROR(0, "no ack mode: unexpected packet %s\n", buf); } for (nc = 0; nc <= last_command; nc++) { - fprintf (stderr, "sending command %s to pid %d\n", commands[nc], pid); - fflush (stderr); + fprintf(stderr, "sending command %s to pid %d\n", commands[nc], pid); + fflush(stderr); /* prepare hexcommand $qRcmd,xxxx....................xx#cc */ - hexcommand = vmalloc (packet_len_for_command (commands[nc])); + hexcommand = vmalloc(packet_len_for_command(commands[nc])); hexcommand[0] = 0; - strcat (hexcommand, "$qRcmd,"); - for (i = 0; i < strlen (commands[nc]); i++) { - sprintf (hex, "%02x", (unsigned char) commands[nc][i]); + strcat(hexcommand, "$qRcmd,"); + for (i = 0; i < strlen(commands[nc]); i++) { + sprintf(hex, "%02x", (unsigned char) commands[nc][i]); // Need to use unsigned char, to avoid sign extension. - strcat (hexcommand, hex); + strcat(hexcommand, hex); } /* checksum (but without the $) */ cksum = 0; - for (hi = 1; hi < strlen (hexcommand); hi++) + for (hi = 1; hi < strlen(hexcommand); hi++) cksum+=hexcommand[hi]; - strcat (hexcommand, "#"); - sprintf (hex, "%02x", cksum); - strcat (hexcommand, hex); - write_buf (to_pid, hexcommand, strlen (hexcommand), - "writing hex command to pid", /* notify */ True); + strcat(hexcommand, "#"); + sprintf(hex, "%02x", cksum); + strcat(hexcommand, hex); + write_buf(to_pid, hexcommand, strlen(hexcommand), + "writing hex command to pid", /* notify */ True); /* we exit of the below loop explicitly when the command has been handled or because a signal handler will set shutting_down. */ while (!shutting_down) { - buflen = getpkt (buf, from_pid, to_pid); + buflen = getpkt(buf, from_pid, to_pid); if (buflen < 0) { - ERROR (0, "error reading packet\n"); + ERROR(0, "error reading packet\n"); if (buflen == -2) - invoker_valgrind_dying (); + invoker_valgrind_dying(); break; } - if (strlen (buf) == 0) { - DEBUG (0, "empty packet rcvd (packet qRcmd not recognised?)\n"); + if (strlen(buf) == 0) { + DEBUG(0, "empty packet rcvd (packet qRcmd not recognised?)\n"); break; } - if (strcmp (buf, "OK") == 0) { - DEBUG (1, "OK packet rcvd\n"); + if (strcmp(buf, "OK") == 0) { + DEBUG(1, "OK packet rcvd\n"); break; } if (buf[0] == 'E') { - DEBUG (0, - "E NN error packet rcvd: %s (unknown monitor command?)\n", - buf); + DEBUG(0, + "E NN error packet rcvd: %s (unknown monitor command?)\n", + buf); break; } if (buf[0] == 'W') { - DEBUG (0, "W stopped packet rcvd: %s\n", buf); + DEBUG(0, "W stopped packet rcvd: %s\n", buf); break; } if (buf[0] == 'T') { - DEBUG (1, "T resume reply packet received: %s\n", buf); + DEBUG(1, "T resume reply packet received: %s\n", buf); continue; } /* must be here an O packet with hex encoded string reply => decode and print it */ if (buf[0] != 'O') { - DEBUG (0, "expecting O packet, received: %s\n", buf); + DEBUG(0, "expecting O packet, received: %s\n", buf); continue; } { char buf_print[buflen/2 + 1]; for (i = 1; i < buflen; i = i + 2) - buf_print[i/2] = (fromhex (*(buf+i)) << 4) - + fromhex (*(buf+i+1)); + buf_print[i/2] = (fromhex(*(buf+i)) << 4) + + fromhex(*(buf+i+1)); buf_print[buflen/2] = 0; - printf ("%s", buf_print); - fflush (stdout); + printf("%s", buf_print); + fflush(stdout); } } - free (hexcommand); + free(hexcommand); } shutting_down = True; - close_connection (to_pid, from_pid); + close_connection(to_pid, from_pid); } /* report to user the existence of a vgdb-able valgrind process @@ -1073,20 +1073,20 @@ void standalone_send_commands (int pid, while producing the command line for pid, as this is not critical and at least on MacOS, reading cmdline is not available. */ static -void report_pid (int pid, Bool on_stdout) +void report_pid(int pid, Bool on_stdout) { char cmdline_file[50]; // large enough int fd, i; FILE *out = on_stdout ? stdout : stderr; - fprintf (out, "use --pid=%d for ", pid); + fprintf(out, "use --pid=%d for ", pid); - sprintf (cmdline_file, "/proc/%d/cmdline", pid); - fd = open (cmdline_file, O_RDONLY); + sprintf(cmdline_file, "/proc/%d/cmdline", pid); + fd = open(cmdline_file, O_RDONLY); if (fd == -1) { - DEBUG (1, "error opening cmdline file %s %s\n", - cmdline_file, strerror (errno)); - fprintf (out, "(could not open process command line)\n"); + DEBUG(1, "error opening cmdline file %s %s\n", + cmdline_file, strerror(errno)); + fprintf(out, "(could not open process command line)\n"); } else { char cmdline[100]; ssize_t sz; @@ -1095,23 +1095,23 @@ void report_pid (int pid, Bool on_stdout) if (cmdline[i] == 0) cmdline[i] = ' '; cmdline[sz] = 0; - fprintf (out, "%s", cmdline); + fprintf(out, "%s", cmdline); } if (sz == -1) { - DEBUG (1, "error reading cmdline file %s %s\n", - cmdline_file, strerror (errno)); - fprintf (out, "(error reading process command line)"); + DEBUG(1, "error reading cmdline file %s %s\n", + cmdline_file, strerror(errno)); + fprintf(out, "(error reading process command line)"); } - fprintf (out, "\n"); - close (fd); + fprintf(out, "\n"); + close(fd); } - fflush (out); + fflush(out); } static -void usage (void) +void usage(void) { - fprintf (stderr, + fprintf(stderr, "Usage: vgdb [OPTION]... [[-c] COMMAND]...\n" "vgdb (valgrind gdb) has two usages\n" " 1. standalone to send monitor commands to a Valgrind gdbserver.\n" @@ -1143,9 +1143,9 @@ void usage (void) "\n" " -h --help shows this message\n" " To get help from the Valgrind gdbserver, use vgdb help\n" -"\n", vgdb_prefix_default () +"\n", vgdb_prefix_default() ); - invoker_restrictions_msg (); + invoker_restrictions_msg(); } /* If show_list, outputs on stdout the list of Valgrind processes with gdbserver activated. @@ -1161,14 +1161,14 @@ void usage (void) or exits in case of error (e.g. no pid found corresponding to arg_pid */ static -int search_arg_pid (int arg_pid, int check_trials, Bool show_list) +int search_arg_pid(int arg_pid, int check_trials, Bool show_list) { int i; int pid = -1; if (arg_pid == 0 || arg_pid < -1) { - fprintf (stderr, "vgdb error: invalid pid %d given\n", arg_pid); - exit (1); + fprintf(stderr, "vgdb error: invalid pid %d given\n", arg_pid); + exit(1); } else { /* search for a matching named fifo. If we have been given a pid, we will check that the matching FIFO is @@ -1178,29 +1178,29 @@ int search_arg_pid (int arg_pid, int check_trials, Bool show_list) If we find multiple processes with valid FIFO, we report them and will exit with an error. */ DIR *vgdb_dir; - char *vgdb_dir_name = vmalloc (strlen (vgdb_prefix) + 3); + char *vgdb_dir_name = vmalloc(strlen (vgdb_prefix) + 3); struct dirent *f; int is; int nr_valid_pid = 0; const char *suffix = "-from-vgdb-to-"; /* followed by pid */ - char *vgdb_format = vmalloc (strlen (vgdb_prefix) + strlen (suffix) + 1); + char *vgdb_format = vmalloc(strlen(vgdb_prefix) + strlen(suffix) + 1); - strcpy (vgdb_format, vgdb_prefix); - strcat (vgdb_format, suffix); + strcpy(vgdb_format, vgdb_prefix); + strcat(vgdb_format, suffix); - if (strchr (vgdb_prefix, '/') != NULL) { - strcpy (vgdb_dir_name, vgdb_prefix); - for (is = strlen (vgdb_prefix) - 1; is >= 0; is--) + if (strchr(vgdb_prefix, '/') != NULL) { + strcpy(vgdb_dir_name, vgdb_prefix); + for (is = strlen(vgdb_prefix) - 1; is >= 0; is--) if (vgdb_dir_name[is] == '/') { vgdb_dir_name[is+1] = '\0'; break; } } else { - strcpy (vgdb_dir_name, ""); + strcpy(vgdb_dir_name, ""); } - DEBUG (1, "searching pid in directory %s format %s\n", - vgdb_dir_name, vgdb_format); + DEBUG(1, "searching pid in directory %s format %s\n", + vgdb_dir_name, vgdb_format); /* try to find FIFOs with valid pid. On exit of the loop, pid is set to: @@ -1210,42 +1210,42 @@ int search_arg_pid (int arg_pid, int check_trials, Bool show_list) otherwise it is set to the (only) pid found that can be debugged */ for (i = 0; i < check_trials; i++) { - DEBUG (1, "check_trial %d \n", i); + DEBUG(1, "check_trial %d \n", i); if (i > 0) /* wait one second before checking again */ - sleep (1); + sleep(1); - vgdb_dir = opendir (strlen (vgdb_dir_name) ? vgdb_dir_name : "./"); + vgdb_dir = opendir(strlen(vgdb_dir_name) ? vgdb_dir_name : "./"); if (vgdb_dir == NULL) - XERROR (errno, - "vgdb error: opening directory %s searching vgdb fifo\n", - vgdb_dir_name); + XERROR(errno, + "vgdb error: opening directory %s searching vgdb fifo\n", + vgdb_dir_name); errno = 0; /* avoid complain if vgdb_dir is empty */ - while ((f = readdir (vgdb_dir))) { + while ((f = readdir(vgdb_dir))) { struct stat st; - char pathname[strlen (vgdb_dir_name) + strlen (f->d_name) + 1]; + char pathname[strlen(vgdb_dir_name) + strlen(f->d_name) + 1]; char *wrongpid; int newpid; - strcpy (pathname, vgdb_dir_name); - strcat (pathname, f->d_name); - DEBUG (3, "checking pathname is FIFO %s\n", pathname); - if (stat (pathname, &st) != 0) { + strcpy(pathname, vgdb_dir_name); + strcat(pathname, f->d_name); + DEBUG(3, "checking pathname is FIFO %s\n", pathname); + if (stat(pathname, &st) != 0) { if (debuglevel >= 3) - ERROR (errno, "vgdb error: stat %s searching vgdb fifo\n", - pathname); - } else if (S_ISFIFO (st.st_mode)) { - DEBUG (3, "trying FIFO %s\n", pathname); - if (strncmp (pathname, vgdb_format, - strlen (vgdb_format)) == 0) { - newpid = strtol (pathname + strlen (vgdb_format), - &wrongpid, 10); + ERROR(errno, "vgdb error: stat %s searching vgdb fifo\n", + pathname); + } else if (S_ISFIFO(st.st_mode)) { + DEBUG(3, "trying FIFO %s\n", pathname); + if (strncmp(pathname, vgdb_format, + strlen(vgdb_format)) == 0) { + newpid = strtol(pathname + strlen(vgdb_format), + &wrongpid, 10); if (*wrongpid == '-' && newpid > 0 - && kill (newpid, 0) == 0) { + && kill(newpid, 0) == 0) { nr_valid_pid++; if (show_list) { - report_pid (newpid, /*on_stdout*/ True); + report_pid(newpid, /*on_stdout*/ True); pid = newpid; } else if (arg_pid != -1) { if (arg_pid == newpid) { @@ -1257,10 +1257,10 @@ int search_arg_pid (int arg_pid, int check_trials, Bool show_list) (stderr, "no --pid= arg given" " and multiple valgrind pids found:\n"); - report_pid (pid, /*on_stdout*/ False); + report_pid(pid, /*on_stdout*/ False); } pid = -2; - report_pid (newpid, /*on_stdout*/ False); + report_pid(newpid, /*on_stdout*/ False); } else { pid = newpid; } @@ -1270,31 +1270,31 @@ int search_arg_pid (int arg_pid, int check_trials, Bool show_list) errno = 0; /* avoid complain if at the end of vgdb_dir */ } if (f == NULL && errno != 0) - XERROR (errno, "vgdb error: reading directory %s for vgdb fifo\n", - vgdb_dir_name); + XERROR(errno, "vgdb error: reading directory %s for vgdb fifo\n", + vgdb_dir_name); - closedir (vgdb_dir); + closedir(vgdb_dir); if (pid != -1) break; } - free (vgdb_dir_name); - free (vgdb_format); + free(vgdb_dir_name); + free(vgdb_format); } if (show_list) { - exit (1); + exit(1); } else if (pid == -1) { if (arg_pid == -1) - fprintf (stderr, "vgdb error: no FIFO found and no pid given\n"); + fprintf(stderr, "vgdb error: no FIFO found and no pid given\n"); else - fprintf (stderr, "vgdb error: no FIFO found matching pid %d\n", - arg_pid); - exit (1); + fprintf(stderr, "vgdb error: no FIFO found matching pid %d\n", + arg_pid); + exit(1); } else if (pid == -2) { /* no arg_pid given, multiple FIFOs found */ - exit (1); + exit(1); } else { return pid; @@ -1306,16 +1306,16 @@ int search_arg_pid (int arg_pid, int check_trials, Bool show_list) from arg. If True is returned, *value contains the extracted value.*/ static -Bool numeric_val (char* arg, int *value) +Bool numeric_val(char* arg, int *value) { - const char *eq_pos = strchr (arg, '='); + const char *eq_pos = strchr(arg, '='); char *wrong; long long int long_value; if (eq_pos == NULL) return False; - long_value = strtoll (eq_pos+1, &wrong, 10); + long_value = strtoll(eq_pos+1, &wrong, 10); if (long_value < 0 || long_value > INT_MAX) return False; if (*wrong) @@ -1327,13 +1327,13 @@ Bool numeric_val (char* arg, int *value) /* true if arg matches the provided option */ static -Bool is_opt (char* arg, const char *option) +Bool is_opt(char* arg, const char *option) { - int option_len = strlen (option); + int option_len = strlen(option); if (option[option_len-1] == '=') - return (0 == strncmp (option, arg, option_len)); + return (0 == strncmp(option, arg, option_len)); else - return (0 == strcmp (option, arg)); + return (0 == strcmp(option, arg)); } /* Parse command lines options. If error(s), exits. @@ -1342,14 +1342,14 @@ Bool is_opt (char* arg, const char *option) On return, *p_last_command gives the position in commands where the last command has been allocated (using vmalloc). */ static -void parse_options (int argc, char** argv, - Bool *p_show_shared_mem, - Bool *p_show_list, - int *p_arg_pid, - int *p_check_trials, - int *p_port, - int *p_last_command, - char *commands[]) +void parse_options(int argc, char** argv, + Bool *p_show_shared_mem, + Bool *p_show_list, + int *p_arg_pid, + int *p_check_trials, + int *p_port, + int *p_last_command, + char *commands[]) { Bool show_shared_mem = False; Bool show_list = False; @@ -1362,71 +1362,71 @@ void parse_options (int argc, char** argv, int arg_errors = 0; for (i = 1; i < argc; i++) { - if (is_opt (argv[i], "--help") || is_opt (argv[i], "-h")) { - usage (); - exit (0); - } else if (is_opt (argv[i], "-d")) { + if (is_opt(argv[i], "--help") || is_opt(argv[i], "-h")) { + usage(); + exit(0); + } else if (is_opt(argv[i], "-d")) { debuglevel++; - } else if (is_opt (argv[i], "-D")) { + } else if (is_opt(argv[i], "-D")) { show_shared_mem = True; - } else if (is_opt (argv[i], "-l")) { + } else if (is_opt(argv[i], "-l")) { show_list = True; - } else if (is_opt (argv[i], "--pid=")) { + } else if (is_opt(argv[i], "--pid=")) { int newpid; - if (!numeric_val (argv[i], &newpid)) { - fprintf (stderr, "invalid --pid argument %s\n", argv[i]); + if (!numeric_val(argv[i], &newpid)) { + fprintf(stderr, "invalid --pid argument %s\n", argv[i]); arg_errors++; } else if (arg_pid != -1) { - fprintf (stderr, "multiple --pid arguments given\n"); + fprintf(stderr, "multiple --pid arguments given\n"); arg_errors++; } else { arg_pid = newpid; } - } else if (is_opt (argv[i], "--wait=")) { - if (!numeric_val (argv[i], &check_trials)) { - fprintf (stderr, "invalid --wait argument %s\n", argv[i]); + } else if (is_opt(argv[i], "--wait=")) { + if (!numeric_val(argv[i], &check_trials)) { + fprintf(stderr, "invalid --wait argument %s\n", argv[i]); arg_errors++; } - } else if (is_opt (argv[i], "--max-invoke-ms=")) { - if (!numeric_val (argv[i], &max_invoke_ms)) { - fprintf (stderr, "invalid --max-invoke-ms argument %s\n", argv[i]); + } else if (is_opt(argv[i], "--max-invoke-ms=")) { + if (!numeric_val(argv[i], &max_invoke_ms)) { + fprintf(stderr, "invalid --max-invoke-ms argument %s\n", argv[i]); arg_errors++; } - } else if (is_opt (argv[i], "--cmd-time-out=")) { - if (!numeric_val (argv[i], &cmd_time_out)) { - fprintf (stderr, "invalid --cmd-time-out argument %s\n", argv[i]); + } else if (is_opt(argv[i], "--cmd-time-out=")) { + if (!numeric_val(argv[i], &cmd_time_out)) { + fprintf(stderr, "invalid --cmd-time-out argument %s\n", argv[i]); arg_errors++; } - } else if (is_opt (argv[i], "--port=")) { - if (!numeric_val (argv[i], &int_port)) { - fprintf (stderr, "invalid --port argument %s\n", argv[i]); + } else if (is_opt(argv[i], "--port=")) { + if (!numeric_val(argv[i], &int_port)) { + fprintf(stderr, "invalid --port argument %s\n", argv[i]); arg_errors++; } - } else if (is_opt (argv[i], "--vgdb-prefix=")) { + } else if (is_opt(argv[i], "--vgdb-prefix=")) { vgdb_prefix = argv[i] + 14; - } else if (is_opt (argv[i], "-c")) { + } else if (is_opt(argv[i], "-c")) { last_command++; - commands[last_command] = vmalloc (1); + commands[last_command] = vmalloc(1); commands[last_command][0] = '\0'; - } else if (0 == strncmp (argv[i], "-", 1)) { - fprintf (stderr, "unknown or invalid argument %s\n", argv[i]); + } else if (0 == strncmp(argv[i], "-", 1)) { + fprintf(stderr, "unknown or invalid argument %s\n", argv[i]); arg_errors++; } else { int len; if (last_command == -1) { /* only one command, no -c command indicator */ last_command++; - commands[last_command] = vmalloc (1); + commands[last_command] = vmalloc(1); commands[last_command][0] = '\0'; } - len = strlen (commands[last_command]); - commands[last_command] = vrealloc (commands[last_command], - len + 1 + strlen (argv[i]) + 1); + len = strlen(commands[last_command]); + commands[last_command] = vrealloc(commands[last_command], + len + 1 + strlen(argv[i]) + 1); if (len > 0) - strcat (commands[last_command], " "); - strcat (commands[last_command], argv[i]); - if (packet_len_for_command (commands[last_command]) > PBUFSIZ) { - fprintf (stderr, "command %s too long\n", commands[last_command]); + strcat(commands[last_command], " "); + strcat(commands[last_command], argv[i]); + if (packet_len_for_command(commands[last_command]) > PBUFSIZ) { + fprintf(stderr, "command %s too long\n", commands[last_command]); arg_errors++; } @@ -1434,47 +1434,47 @@ void parse_options (int argc, char** argv, } if (vgdb_prefix == NULL) - vgdb_prefix = vgdb_prefix_default (); + vgdb_prefix = vgdb_prefix_default(); - if (isatty (0) + if (isatty(0) && !show_shared_mem && !show_list && int_port == 0 && last_command == -1) { arg_errors++; - fprintf (stderr, - "Using vgdb standalone implies to give -D or -l or a COMMAND\n"); + fprintf(stderr, + "Using vgdb standalone implies to give -D or -l or a COMMAND\n"); } if (show_shared_mem && show_list) { arg_errors++; - fprintf (stderr, - ... [truncated message content] |
|
From: Mark W. <ma...@kl...> - 2018-11-06 08:46:18
|
On Mon, 2018-11-05 at 22:07 +0100, Philippe Waroquiers wrote: > On Mon, 2018-11-05 at 13:24 +1100, Nicholas Nethercote wrote: > > Why'd you do that? This file's style is now less like the style used throughout most of this codebase and most other C/C++ codebases. > > Humph, it looks like I was recently too much working on GDB, that follows > the GNU coding style which mandates 'function (arg' (this is also > used > at my work). Yes, I like GNU style most since that is more consistent with almost every other code base I work on. > But effectively, doing some grep on the valgrind code basis, we have > various different styles such as > 'function(arg' > 'function (arg' > 'function ( arg' > 'function( arg' > > but it looks like valgrind uses more the first style than the 3 > others. > So, I will rather switch back to the first style 'function(arg'. Although I like the second (GNU) style the most, it is probably best to use something consistent inside the code base like the first (except for imported code like the libiberty demangler). Cheers, Mark |
|
From: Julian S. <js...@ac...> - 2018-11-06 08:15:22
|
> But effectively, doing some grep on the valgrind code basis, we have > various different styles such as > 'function(arg' > 'function (arg' > 'function ( arg' > 'function( arg' > > but it looks like valgrind uses more the first style than the 3 others. > So, I will rather switch back to the first style 'function(arg'. It probably is somewhat inconsistent, but yes, I would also prefer the first style, "function(arg". J |
|
From: Eliot M. <mo...@cs...> - 2018-11-06 06:17:05
|
I have found this style to be quite useful: function (arg, ...) for declarations, and function(arg, ...) for calls. This makes it easy to search in a file for the declaration as opposed to the uses. Best - EM |
|
From: Nicholas N. <n.n...@gm...> - 2018-11-06 00:27:39
|
Thanks! My perception is that `function(arg` and `function( arg` are the most common, and I personally have a strong preference for the former. Also, I think the GNU coding style is an abomination. (Especially how it treats braces!) Nick On Tue, Nov 6, 2018 at 8:07 AM Philippe Waroquiers < phi...@sk...> wrote: > On Mon, 2018-11-05 at 13:24 +1100, Nicholas Nethercote wrote: > > Why'd you do that? This file's style is now less like the style used > throughout most of this codebase and most other C/C++ codebases. > Humph, it looks like I was recently too much working on GDB, that follows > the GNU coding style which mandates 'function (arg' (this is also used > at my work). > > But effectively, doing some grep on the valgrind code basis, we have > various different styles such as > 'function(arg' > 'function (arg' > 'function ( arg' > 'function( arg' > > but it looks like valgrind uses more the first style than the 3 others. > So, I will rather switch back to the first style 'function(arg'. > > Thanks for the comment > > Philippe > > |
|
From: Philippe W. <phi...@sk...> - 2018-11-05 21:07:43
|
On Mon, 2018-11-05 at 13:24 +1100, Nicholas Nethercote wrote: > Why'd you do that? This file's style is now less like the style used throughout most of this codebase and most other C/C++ codebases. Humph, it looks like I was recently too much working on GDB, that follows the GNU coding style which mandates 'function (arg' (this is also used at my work). But effectively, doing some grep on the valgrind code basis, we have various different styles such as 'function(arg' 'function (arg' 'function ( arg' 'function( arg' but it looks like valgrind uses more the first style than the 3 others. So, I will rather switch back to the first style 'function(arg'. Thanks for the comment Philippe |
|
From: Philippe W. <phi...@so...> - 2018-11-04 10:49:27
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=8a6fe39d2a374f5cfffbd052467f35bf115797a4 commit 8a6fe39d2a374f5cfffbd052467f35bf115797a4 Author: Philippe Waroquiers <phi...@sk...> Date: Sun Nov 4 11:48:00 2018 +0100 Make white space style more consistent, no functional impact. Consistently use a space between function name and function arg list. Diff: --- coregrind/vgdb.c | 700 +++++++++++++++++++++++++++---------------------------- 1 file changed, 350 insertions(+), 350 deletions(-) diff --git a/coregrind/vgdb.c b/coregrind/vgdb.c index 12d2c7f..5ae5e04 100644 --- a/coregrind/vgdb.c +++ b/coregrind/vgdb.c @@ -55,7 +55,7 @@ It is made of a main program which reads arguments. If no arguments are given or only --pid and --vgdb-prefix, then usage 1 is assumed. - + As relay application, vgdb reads bytes from gdb on stdin and writes these bytes to valgrind. Bytes read from valgrind are written to gdb on stdout. Read/Write from/to valgrind is done @@ -87,17 +87,17 @@ VgdbShared64 *shared64; #define VS_vgdb_pid (shared32 != NULL ? shared32->vgdb_pid : shared64->vgdb_pid) -void *vmalloc(size_t size) +void *vmalloc (size_t size) { - void * mem = malloc(size); + void * mem = malloc (size); if (mem == NULL) XERROR (errno, "can't allocate memory\n"); return mem; } -void *vrealloc(void *ptr,size_t size) +void *vrealloc (void *ptr,size_t size) { - void * mem = realloc(ptr, size); + void * mem = realloc (ptr, size); if (mem == NULL) XERROR (errno, "can't reallocate memory\n"); return mem; @@ -105,11 +105,11 @@ void *vrealloc(void *ptr,size_t size) /* Return the name of a directory for temporary files. */ static -const char *vgdb_tmpdir(void) +const char *vgdb_tmpdir (void) { const char *tmpdir; - tmpdir = getenv("TMPDIR"); + tmpdir = getenv ("TMPDIR"); if (tmpdir == NULL || *tmpdir == '\0') tmpdir = VG_TMPDIR; if (tmpdir == NULL || *tmpdir == '\0') @@ -121,29 +121,29 @@ const char *vgdb_tmpdir(void) /* Return the default path prefix for the named pipes (FIFOs) used by vgdb/gdb to communicate with valgrind */ static -char *vgdb_prefix_default(void) +char *vgdb_prefix_default (void) { static HChar *prefix; if (prefix == NULL) { - const char *tmpdir = vgdb_tmpdir(); - prefix = vmalloc(strlen(tmpdir) + strlen("/vgdb-pipe") + 1); - strcpy(prefix, tmpdir); - strcat(prefix, "/vgdb-pipe"); + const char *tmpdir = vgdb_tmpdir (); + prefix = vmalloc (strlen (tmpdir) + strlen ("/vgdb-pipe") + 1); + strcpy (prefix, tmpdir); + strcat (prefix, "/vgdb-pipe"); } return prefix; } -/* add nrw to the written_by_vgdb field of shared32 or shared64 */ +/* add nrw to the written_by_vgdb field of shared32 or shared64 */ static -void add_written(int nrw) +void add_written (int nrw) { - if (shared32 != NULL) + if (shared32 != NULL) shared32->written_by_vgdb += nrw; - else if (shared64 != NULL) + else if (shared64 != NULL) shared64->written_by_vgdb += nrw; else - assert(0); + assert (0); } static int shared_mem_fd = -1; @@ -152,18 +152,18 @@ void map_vgdbshared (char* shared_mem) { struct stat fdstat; void **s; - shared_mem_fd = open(shared_mem, O_RDWR); + shared_mem_fd = open (shared_mem, O_RDWR); /* shared_mem_fd will not be closed till vgdb exits. */ if (shared_mem_fd == -1) XERROR (errno, "error opening %s shared memory file\n", shared_mem); - if (fstat(shared_mem_fd, &fdstat) != 0) + if (fstat (shared_mem_fd, &fdstat) != 0) XERROR (errno, "fstat"); - if (fdstat.st_size == sizeof(VgdbShared64)) + if (fdstat.st_size == sizeof (VgdbShared64)) s = (void*) &shared64; - else if (fdstat.st_size == sizeof(VgdbShared32)) + else if (fdstat.st_size == sizeof (VgdbShared32)) s = (void*) &shared32; else #if VEX_HOST_WORDSIZE == 8 @@ -171,14 +171,14 @@ void map_vgdbshared (char* shared_mem) "error size shared memory file %s.\n" "expecting size %d (64bits) or %d (32bits) got %ld.\n", shared_mem, - (int) sizeof(VgdbShared64), (int) sizeof(VgdbShared32), + (int) sizeof (VgdbShared64), (int) sizeof (VgdbShared32), (long int)fdstat.st_size); #elif VEX_HOST_WORDSIZE == 4 XERROR (0, "error size shared memory file %s.\n" "expecting size %d (32bits) got %ld.\n", shared_mem, - (int) sizeof(VgdbShared32), + (int) sizeof (VgdbShared32), fdstat.st_size); #else # error "unexpected wordsize" @@ -190,8 +190,8 @@ void map_vgdbshared (char* shared_mem) /* But we can use a 64 bits vgdb with a 32 bits valgrind */ #endif - *s = (void*) mmap (NULL, fdstat.st_size, - PROT_READ|PROT_WRITE, MAP_SHARED, + *s = (void*) mmap (NULL, fdstat.st_size, + PROT_READ|PROT_WRITE, MAP_SHARED, shared_mem_fd, 0); if (*s == (void *) -1) @@ -208,7 +208,7 @@ static int max_invoke_ms = 100; #define NEVER 99999999 static int cmd_time_out = NEVER; static -void *invoke_gdbserver_in_valgrind(void *v_pid) +void *invoke_gdbserver_in_valgrind (void *v_pid) { struct timeval cmd_max_end_time; Bool cmd_started = False; @@ -217,32 +217,32 @@ void *invoke_gdbserver_in_valgrind(void *v_pid) int pid = *(int *)v_pid; int written_by_vgdb_before_sleep; int seen_by_valgrind_before_sleep; - + int invoked_written = -1; unsigned int usecs; - pthread_cleanup_push(invoker_cleanup_restore_and_detach, v_pid); + pthread_cleanup_push (invoker_cleanup_restore_and_detach, v_pid); while (!shutting_down) { written_by_vgdb_before_sleep = VS_written_by_vgdb; seen_by_valgrind_before_sleep = VS_seen_by_valgrind; - DEBUG(3, - "written_by_vgdb_before_sleep %d " - "seen_by_valgrind_before_sleep %d\n", - written_by_vgdb_before_sleep, - seen_by_valgrind_before_sleep); + DEBUG (3, + "written_by_vgdb_before_sleep %d " + "seen_by_valgrind_before_sleep %d\n", + written_by_vgdb_before_sleep, + seen_by_valgrind_before_sleep); if (cmd_time_out != NEVER && !cmd_started && written_by_vgdb_before_sleep > seen_by_valgrind_before_sleep) { /* A command was started. Record the time at which it was started. */ - DEBUG(1, "IO for command started\n"); - gettimeofday(&cmd_max_end_time, NULL); + DEBUG (1, "IO for command started\n"); + gettimeofday (&cmd_max_end_time, NULL); cmd_max_end_time.tv_sec += cmd_time_out; cmd_started = True; } if (max_invoke_ms > 0) { usecs = 1000 * max_invoke_ms; - gettimeofday(&invoke_time, NULL); + gettimeofday (&invoke_time, NULL); invoke_time.tv_sec += max_invoke_ms / 1000; invoke_time.tv_usec += 1000 * (max_invoke_ms % 1000); invoke_time.tv_sec += invoke_time.tv_usec / (1000 * 1000); @@ -257,7 +257,7 @@ void *invoke_gdbserver_in_valgrind(void *v_pid) if (usecs == 0 || usecs > 1000 * 1000) usecs = 1000 * 1000; } - usleep(usecs); + usleep (usecs); /* If nothing happened during our sleep, let's try to wake up valgrind or check for cmd time out. */ @@ -265,23 +265,23 @@ void *invoke_gdbserver_in_valgrind(void *v_pid) && seen_by_valgrind_before_sleep == VS_seen_by_valgrind && VS_written_by_vgdb > VS_seen_by_valgrind) { struct timeval now; - gettimeofday(&now, NULL); - DEBUG(2, - "after sleep " - "written_by_vgdb %d " - "seen_by_valgrind %d " - "invoked_written %d\n", - VS_written_by_vgdb, - VS_seen_by_valgrind, - invoked_written); + gettimeofday (&now, NULL); + DEBUG (2, + "after sleep " + "written_by_vgdb %d " + "seen_by_valgrind %d " + "invoked_written %d\n", + VS_written_by_vgdb, + VS_seen_by_valgrind, + invoked_written); /* if the pid does not exist anymore, we better stop */ - if (kill(pid, 0) != 0) - XERROR (errno, + if (kill (pid, 0) != 0) + XERROR (errno, "invoke_gdbserver_in_valgrind: " "check for pid %d existence failed\n", pid); if (cmd_started) { if (timercmp (&now, &cmd_max_end_time, >)) - XERROR (0, + XERROR (0, "pid %d did not handle a command in %d seconds\n", pid, cmd_time_out); } @@ -289,7 +289,7 @@ void *invoke_gdbserver_in_valgrind(void *v_pid) /* only need to wake up if the nr written has changed since last invoke. */ if (invoked_written != written_by_vgdb_before_sleep) { - if (invoker_invoke_gdbserver(pid)) { + if (invoker_invoke_gdbserver (pid)) { /* If invoke successful, no need to invoke again for the same value of written_by_vgdb_before_sleep. */ invoked_written = written_by_vgdb_before_sleep; @@ -299,12 +299,12 @@ void *invoke_gdbserver_in_valgrind(void *v_pid) } else { // Something happened => restart timer check. if (cmd_time_out != NEVER) { - DEBUG(2, "some IO was done => restart command\n"); + DEBUG (2, "some IO was done => restart command\n"); cmd_started = False; } } } - pthread_cleanup_pop(0); + pthread_cleanup_pop (0); return NULL; } @@ -312,12 +312,12 @@ static int open_fifo (const char* name, int flags, const char* desc) { int fd; - DEBUG(1, "opening %s %s\n", name, desc); - fd = open(name, flags); + DEBUG (1, "opening %s %s\n", name, desc); + fd = open (name, flags); if (fd == -1) XERROR (errno, "error opening %s %s\n", name, desc); - DEBUG(1, "opened %s %s fd %d\n", name, desc, fd); + DEBUG (1, "opened %s %s fd %d\n", name, desc, fd); return fd; } @@ -333,26 +333,26 @@ void acquire_lock (int fd, int valgrind_pid) fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 1; - if (fcntl(fd, F_SETLK, &fl) < 0) { + if (fcntl (fd, F_SETLK, &fl) < 0) { if (errno == EAGAIN || errno == EACCES) { - XERROR(errno, - "Cannot acquire lock.\n" - "Probably vgdb pid %d already speaks with Valgrind pid %d\n", - VS_vgdb_pid, - valgrind_pid); + XERROR (errno, + "Cannot acquire lock.\n" + "Probably vgdb pid %d already speaks with Valgrind pid %d\n", + VS_vgdb_pid, + valgrind_pid); } else { - XERROR(errno, "cannot acquire lock.\n"); + XERROR (errno, "cannot acquire lock.\n"); } } /* Here, we have the lock. It will be released when fd will be closed. */ /* We indicate our pid to Valgrind gdbserver */ if (shared32 != NULL) - shared32->vgdb_pid = getpid(); + shared32->vgdb_pid = getpid (); else if (shared64 != NULL) - shared64->vgdb_pid = getpid(); + shared64->vgdb_pid = getpid (); else - assert(0); + assert (0); } #define PBUFSIZ 16384 /* keep in sync with server.h */ @@ -364,42 +364,42 @@ static int read_buf (int fd, char* buf, const char* desc) { int nrread; - DEBUG(2, "reading %s\n", desc); - nrread = read(fd, buf, PBUFSIZ); + DEBUG (2, "reading %s\n", desc); + nrread = read (fd, buf, PBUFSIZ); if (nrread == -1) { ERROR (errno, "error reading %s\n", desc); return -1; } buf[nrread] = '\0'; - DEBUG(2, "read %s %s\n", desc, buf); + DEBUG (2, "read %s %s\n", desc, buf); return nrread; } /* write size bytes from buf to fd. desc is a description of the action for which the write is done. - If notify, then add size to the shared cntr indicating to the + If notify, then add size to the shared cntr indicating to the valgrind process that there is new data. Returns True if write is ok, False if there was a problem. */ static -Bool write_buf(int fd, const char* buf, int size, const char* desc, Bool notify) +Bool write_buf (int fd, const char* buf, int size, const char* desc, Bool notify) { int nrwritten; int nrw; - DEBUG(2, "writing %s len %d %.*s notify: %d\n", desc, size, - size, buf, notify); + DEBUG (2, "writing %s len %d %.*s notify: %d\n", desc, size, + size, buf, notify); nrwritten = 0; while (nrwritten < size) { nrw = write (fd, buf+nrwritten, size - nrwritten); if (nrw == -1) { - ERROR(errno, "error write %s\n", desc); + ERROR (errno, "error write %s\n", desc); return False; } nrwritten = nrwritten + nrw; if (notify) - add_written(nrw); + add_written (nrw); } return True; -} +} typedef enum { FROM_GDB, @@ -407,7 +407,7 @@ typedef enum { FROM_PID, TO_PID } ConnectionKind; static const int NumConnectionKind = TO_PID+1; -static +static const char *ppConnectionKind (ConnectionKind con) { switch (con) { @@ -427,22 +427,22 @@ static char *from_gdb_to_pid; /* fifo name to write gdb command to pid */ Returns False in case of error. to_pid is the file descriptor to write to the process pid. */ static -Bool read_from_gdb_write_to_pid(int to_pid) +Bool read_from_gdb_write_to_pid (int to_pid) { char buf[PBUFSIZ+1]; // +1 for trailing \0 int nrread; - nrread = read_buf(from_gdb, buf, "from gdb on stdin"); + nrread = read_buf (from_gdb, buf, "from gdb on stdin"); if (nrread <= 0) { - if (nrread == 0) - DEBUG(1, "read 0 bytes from gdb => assume exit\n"); + if (nrread == 0) + DEBUG (1, "read 0 bytes from gdb => assume exit\n"); else - DEBUG(1, "error reading bytes from gdb\n"); + DEBUG (1, "error reading bytes from gdb\n"); close (from_gdb); shutting_down = True; return False; } - return write_buf(to_pid, buf, nrread, "to_pid", /* notify */ True); + return write_buf (to_pid, buf, nrread, "to_pid", /* notify */ True); } static int to_gdb = 1; /* stdout by default, changed if --port is given. */ @@ -451,22 +451,22 @@ static char *to_gdb_from_pid; /* fifo name to read pid replies */ Returns False in case of error. from_pid is the file descriptor to read data from the process pid. */ static -Bool read_from_pid_write_to_gdb(int from_pid) +Bool read_from_pid_write_to_gdb (int from_pid) { char buf[PBUFSIZ+1]; // +1 for trailing \0 int nrread; - nrread = read_buf(from_pid, buf, "from pid"); + nrread = read_buf (from_pid, buf, "from pid"); if (nrread <= 0) { - if (nrread == 0) - DEBUG(1, "read 0 bytes from pid => assume exit\n"); + if (nrread == 0) + DEBUG (1, "read 0 bytes from pid => assume exit\n"); else - DEBUG(1, "error reading bytes from pid\n"); + DEBUG (1, "error reading bytes from pid\n"); close (from_pid); shutting_down = True; return False; } - return write_buf(to_gdb, buf, nrread, "to_gdb", /* notify */ False); + return write_buf (to_gdb, buf, nrread, "to_gdb", /* notify */ False); } static @@ -474,71 +474,71 @@ void wait_for_gdb_connect (int in_port) { struct sockaddr_in addr; - int listen_gdb = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + int listen_gdb = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP); int gdb_connect; - + if (-1 == listen_gdb) { - XERROR(errno, "cannot create socket"); + XERROR (errno, "cannot create socket"); } - - memset(&addr, 0, sizeof(addr)); - + + memset (&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; - addr.sin_port = htons((unsigned short int)in_port); + addr.sin_port = htons ((unsigned short int)in_port); addr.sin_addr.s_addr = INADDR_ANY; - - if (-1 == bind(listen_gdb,(struct sockaddr *)&addr, sizeof(addr))) { - XERROR(errno, "bind failed"); + + if (-1 == bind (listen_gdb, (struct sockaddr *)&addr, sizeof(addr))) { + XERROR (errno, "bind failed"); } - fprintf(stderr, "listening on port %d ...", in_port); - fflush(stderr); - if (-1 == listen(listen_gdb, 1)) { - XERROR(errno, "error listen failed"); + fprintf (stderr, "listening on port %d ...", in_port); + fflush (stderr); + if (-1 == listen (listen_gdb, 1)) { + XERROR (errno, "error listen failed"); } - gdb_connect = accept(listen_gdb, NULL, NULL); + gdb_connect = accept (listen_gdb, NULL, NULL); if (gdb_connect < 0) { - XERROR(errno, "accept failed"); + XERROR (errno, "accept failed"); } - fprintf(stderr, "connected.\n"); - fflush(stderr); - close(listen_gdb); + fprintf (stderr, "connected.\n"); + fflush (stderr); + close (listen_gdb); from_gdb = gdb_connect; to_gdb = gdb_connect; } /* prepares the FIFOs filenames, map the shared memory. */ static -void prepare_fifos_and_shared_mem(int pid) +void prepare_fifos_and_shared_mem (int pid) { const HChar *user, *host; unsigned len; - user = getenv("LOGNAME"); - if (user == NULL) user = getenv("USER"); + user = getenv ("LOGNAME"); + if (user == NULL) user = getenv ("USER"); if (user == NULL) user = "???"; - if (strchr(user, '/')) user = "???"; + if (strchr (user, '/')) user = "???"; - host = getenv("HOST"); - if (host == NULL) host = getenv("HOSTNAME"); + host = getenv ("HOST"); + if (host == NULL) host = getenv ("HOSTNAME"); if (host == NULL) host = "???"; - if (strchr(host, '/')) host = "???"; + if (strchr (host, '/')) host = "???"; - len = strlen(vgdb_prefix) + strlen(user) + strlen(host) + 40; + len = strlen (vgdb_prefix) + strlen (user) + strlen (host) + 40; from_gdb_to_pid = vmalloc (len); to_gdb_from_pid = vmalloc (len); shared_mem = vmalloc (len); /* below 3 lines must match the equivalent in remote-utils.c */ - sprintf(from_gdb_to_pid, "%s-from-vgdb-to-%d-by-%s-on-%s", vgdb_prefix, - pid, user, host); - sprintf(to_gdb_from_pid, "%s-to-vgdb-from-%d-by-%s-on-%s", vgdb_prefix, - pid, user, host); - sprintf(shared_mem, "%s-shared-mem-vgdb-%d-by-%s-on-%s", vgdb_prefix, - pid, user, host); - DEBUG (1, "vgdb: using %s %s %s\n", + sprintf (from_gdb_to_pid, "%s-from-vgdb-to-%d-by-%s-on-%s", vgdb_prefix, + pid, user, host); + sprintf (to_gdb_from_pid, "%s-to-vgdb-from-%d-by-%s-on-%s", vgdb_prefix, + pid, user, host); + sprintf (shared_mem, "%s-shared-mem-vgdb-%d-by-%s-on-%s", vgdb_prefix, + pid, user, host); + DEBUG (1, "vgdb: using %s %s %s\n", from_gdb_to_pid, to_gdb_from_pid, shared_mem); - map_vgdbshared(shared_mem); + map_vgdbshared (shared_mem); } /* Convert hex digit A to a number. */ @@ -551,7 +551,7 @@ fromhex (int a) else if (a >= 'a' && a <= 'f') return a - 'a' + 10; else - XERROR(0, "Reply contains invalid hex digit %c\n", a); + XERROR (0, "Reply contains invalid hex digit %c\n", a); return 0; } @@ -562,7 +562,7 @@ readchar (int fd) { static char buf[PBUFSIZ+1]; // +1 for trailing \0 static int bufcnt = 0; - static unsigned char *bufp; + static unsigned char *bufp; // unsigned bufp to e.g. avoid having 255 converted to int -1 if (bufcnt-- > 0) @@ -595,7 +595,7 @@ getpkt (char *buf, int fromfd, int ackfd) char *bp; unsigned char csum, c1, c2; int c; - + while (1) { csum = 0; @@ -603,7 +603,7 @@ getpkt (char *buf, int fromfd, int ackfd) c = readchar (fromfd); if (c == '$') break; - DEBUG(2, "[getpkt: discarding char '%c']\n", c); + DEBUG (2, "[getpkt: discarding char '%c']\n", c); if (c < 0) return c; } @@ -641,12 +641,12 @@ getpkt (char *buf, int fromfd, int ackfd) fprintf (stderr, "Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n", (c1 << 4) + c2, csum, buf); if (write (ackfd, "-", 1) != 1) - ERROR(0, "error when writing - (nack)\n"); + ERROR (0, "error when writing - (nack)\n"); else - add_written(1); + add_written (1); } - DEBUG(2, "getpkt (\"%s\"); [no ack] \n", buf); + DEBUG (2, "getpkt (\"%s\"); [no ack] \n", buf); return bp - buf; } @@ -668,8 +668,8 @@ void received_signal (int signum) sigusr1++; if (sigusr1_fd >= 0) { char control_c = '\003'; - write_buf(sigusr1_fd, &control_c, 1, - "write \\003 on SIGUSR1", /* notify */ True); + write_buf (sigusr1_fd, &control_c, 1, + "write \\003 on SIGUSR1", /* notify */ True); } } else if (signum == SIGTERM) { @@ -682,38 +682,38 @@ void received_signal (int signum) sigpipe++; } else if (signum == SIGALRM) { sigalrm++; -#if defined(VGPV_arm_linux_android) \ - || defined(VGPV_x86_linux_android) \ - || defined(VGPV_mips32_linux_android) \ - || defined(VGPV_arm64_linux_android) +#if defined (VGPV_arm_linux_android) \ + || defined (VGPV_x86_linux_android) \ + || defined (VGPV_mips32_linux_android) \ + || defined (VGPV_arm64_linux_android) /* Android has no pthread_cancel. As it also does not have an invoker implementation, there is no need for cleanup action. So, we just do nothing. */ - DEBUG(1, "sigalrm received, no action on android\n"); + DEBUG (1, "sigalrm received, no action on android\n"); #else /* Note: we cannot directly invoke restore_and_detach : this must - be done by the thread that has attached. + be done by the thread that has attached. We have in this thread pushed a cleanup handler that will cleanup what is needed. */ - DEBUG(1, "pthread_cancel invoke_gdbserver_in_valgrind_thread\n"); - pthread_cancel(invoke_gdbserver_in_valgrind_thread); + DEBUG (1, "pthread_cancel invoke_gdbserver_in_valgrind_thread\n"); + pthread_cancel (invoke_gdbserver_in_valgrind_thread); #endif } else { - ERROR(0, "unexpected signal %d\n", signum); + ERROR (0, "unexpected signal %d\n", signum); } } /* install the signal handlers allowing e.g. vgdb to cleanup in case of termination. */ static -void install_handlers(void) +void install_handlers (void) { struct sigaction action, oldaction; action.sa_handler = received_signal; sigemptyset (&action.sa_mask); action.sa_flags = 0; - + /* SIGINT: when user types C-c in gdb, this sends a SIGINT to vgdb + causes a character to be sent to remote gdbserver. The later is enough to wakeup the valgrind process. */ @@ -728,20 +728,20 @@ void install_handlers(void) vgdb receives this signal, it will simulate the user typing C-c. */ if (sigaction (SIGUSR1, &action, &oldaction) != 0) XERROR (errno, "vgdb error sigaction SIGUSR1\n"); - + /* SIGTERM: can receive this signal (e.g. from gdb) to terminate vgdb when detaching or similar. A clean shutdown will be done as both the read and write side will detect an end of file. */ if (sigaction (SIGTERM, &action, &oldaction) != 0) XERROR (errno, "vgdb error sigaction SIGTERM\n"); - + /* SIGPIPE: can receive this signal when gdb detaches or kill the process debugged: gdb will close its pipes to vgdb. vgdb must resist to this signal to allow a clean shutdown. */ if (sigaction (SIGPIPE, &action, &oldaction) != 0) XERROR (errno, "vgdb error sigaction SIGPIPE\n"); - + /* SIGALRM: in case invoke thread is blocked, alarm is used to cleanup. */ if (sigaction (SIGALRM, &action, &oldaction) != 0) @@ -755,10 +755,10 @@ void install_handlers(void) /* close the FIFOs provided connections, terminate the invoker thread. */ static -void close_connection(int to_pid, int from_pid) +void close_connection (int to_pid, int from_pid) { - DEBUG(1, "nr received signals: sigint %d sigterm %d sighup %d sigpipe %d\n", - sigint, sigterm, sighup, sigpipe); + DEBUG (1, "nr received signals: sigint %d sigterm %d sighup %d sigpipe %d\n", + sigint, sigterm, sighup, sigpipe); /* Note that we do not forward sigterm to the valgrind process: a sigterm signal is (probably) received from gdb if the user wants to kill the debugged process. The kill instruction has been given to @@ -768,8 +768,8 @@ void close_connection(int to_pid, int from_pid) terminates its gdbserver work. We keep the from pid fifo opened till the invoker thread is finished. This allows the gdbserver to finish sending its last reply. */ - if (close(to_pid) != 0) - ERROR(errno, "close to_pid\n"); + if (close (to_pid) != 0) + ERROR (errno, "close to_pid\n"); /* if there is a task that was busy trying to wake up valgrind process, we wait for it to be terminated otherwise threads @@ -804,15 +804,15 @@ void close_connection(int to_pid, int from_pid) otherwise, valgrind will stop abnormally with SIGSTOP. */ (void) alarm (3); - DEBUG(1, "joining with invoke_gdbserver_in_valgrind_thread\n"); - join = pthread_join(invoke_gdbserver_in_valgrind_thread, NULL); + DEBUG (1, "joining with invoke_gdbserver_in_valgrind_thread\n"); + join = pthread_join (invoke_gdbserver_in_valgrind_thread, NULL); if (join != 0) - XERROR - (join, + XERROR + (join, "vgdb error pthread_join invoke_gdbserver_in_valgrind_thread\n"); } - if (close(from_pid) != 0) - ERROR(errno, "close from_pid\n"); + if (close (from_pid) != 0) + ERROR (errno, "close from_pid\n"); } /* Relay data between gdb and Valgrind gdbserver, till EOF or an @@ -828,12 +828,12 @@ void gdb_relay (int pid) fflush (stderr); if (max_invoke_ms > 0) - pthread_create(&invoke_gdbserver_in_valgrind_thread, NULL, - invoke_gdbserver_in_valgrind, (void *) &pid); - to_pid = open_fifo(from_gdb_to_pid, O_WRONLY, "write to pid"); + pthread_create (&invoke_gdbserver_in_valgrind_thread, NULL, + invoke_gdbserver_in_valgrind, (void *) &pid); + to_pid = open_fifo (from_gdb_to_pid, O_WRONLY, "write to pid"); acquire_lock (shared_mem_fd, pid); - - from_pid = open_fifo (to_gdb_from_pid, O_RDONLY|O_NONBLOCK, + + from_pid = open_fifo (to_gdb_from_pid, O_RDONLY|O_NONBLOCK, "read mode from pid"); sigusr1_fd = to_pid; /* allow simulating user typing control-c */ @@ -842,7 +842,7 @@ void gdb_relay (int pid) ConnectionKind ck; int ret; struct pollfd pollfds[NumConnectionKind]; - + /* watch data written by gdb, watch POLLERR on both gdb fd */ pollfds[FROM_GDB].fd = from_gdb; pollfds[FROM_GDB].events = POLLIN; @@ -850,7 +850,7 @@ void gdb_relay (int pid) pollfds[TO_GDB].fd = to_gdb; pollfds[TO_GDB].events = 0; pollfds[TO_GDB].revents = 0; - + /* watch data written by pid, watch POLLERR on both pid fd */ pollfds[FROM_PID].fd = from_pid; pollfds[FROM_PID].events = POLLIN; @@ -858,13 +858,13 @@ void gdb_relay (int pid) pollfds[TO_PID].fd = to_pid; pollfds[TO_PID].events = 0; pollfds[TO_PID].revents = 0; - - ret = poll(pollfds, - NumConnectionKind, - (shutting_down ? - 1 /* one second */ - : -1 /* infinite */)); - DEBUG(2, "poll ret %d errno %d\n", ret, errno); + + ret = poll (pollfds, + NumConnectionKind, + (shutting_down ? + 1 /* one second */ + : -1 /* infinite */)); + DEBUG (2, "poll ret %d errno %d\n", ret, errno); /* check for unexpected error */ if (ret <= 0 && errno != EINTR) { @@ -872,21 +872,21 @@ void gdb_relay (int pid) shutting_down = True; break; } - + /* check for data to read */ for (ck = 0; ck < NumConnectionKind; ck ++) { if (pollfds[ck].revents & POLLIN) { switch (ck) { - case FROM_GDB: - if (!read_from_gdb_write_to_pid(to_pid)) + case FROM_GDB: + if (!read_from_gdb_write_to_pid (to_pid)) shutting_down = True; break; case FROM_PID: - if (!read_from_pid_write_to_gdb(from_pid)) + if (!read_from_pid_write_to_gdb (from_pid)) shutting_down = True; break; - default: XERROR(0, "unexpected POLLIN on %s\n", - ppConnectionKind(ck)); + default: XERROR (0, "unexpected POLLIN on %s\n", + ppConnectionKind (ck)); } } } @@ -894,25 +894,25 @@ void gdb_relay (int pid) /* check for an fd being in error condition */ for (ck = 0; ck < NumConnectionKind; ck ++) { if (pollfds[ck].revents & POLLERR) { - DEBUG(1, "connection %s fd %d POLLERR error condition\n", - ppConnectionKind(ck), pollfds[ck].fd); - invoker_valgrind_dying(); + DEBUG (1, "connection %s fd %d POLLERR error condition\n", + ppConnectionKind (ck), pollfds[ck].fd); + invoker_valgrind_dying (); shutting_down = True; } if (pollfds[ck].revents & POLLHUP) { - DEBUG(1, "connection %s fd %d POLLHUP error condition\n", - ppConnectionKind(ck), pollfds[ck].fd); - invoker_valgrind_dying(); + DEBUG (1, "connection %s fd %d POLLHUP error condition\n", + ppConnectionKind (ck), pollfds[ck].fd); + invoker_valgrind_dying (); shutting_down = True; } if (pollfds[ck].revents & POLLNVAL) { - DEBUG(1, "connection %s fd %d POLLNVAL error condition\n", - ppConnectionKind(ck), pollfds[ck].fd); - invoker_valgrind_dying(); + DEBUG (1, "connection %s fd %d POLLNVAL error condition\n", + ppConnectionKind (ck), pollfds[ck].fd); + invoker_valgrind_dying (); shutting_down = True; } } - + if (shutting_down) { /* we let some time to the final packets to be transferred */ shutdown_loop++; @@ -920,22 +920,22 @@ void gdb_relay (int pid) break; } } - close_connection(to_pid, from_pid); + close_connection (to_pid, from_pid); } -static int packet_len_for_command(char *cmd) +static int packet_len_for_command (char *cmd) { /* cmd will be send as a packet $qRcmd,xxxx....................xx#cc */ - return 7+ 2*strlen(cmd) +3 + 1; + return 7+ 2*strlen (cmd) +3 + 1; } /* hyper-minimal protocol implementation that sends the provided commands (using qRcmd packets) and read and display their replies. */ static -void standalone_send_commands(int pid, - int last_command, - char *commands[] ) +void standalone_send_commands (int pid, + int last_command, + char *commands[] ) { int from_pid = -1; /* fd to read from pid */ int to_pid = -1; /* fd to write to pid */ @@ -951,10 +951,10 @@ void standalone_send_commands(int pid, if (max_invoke_ms > 0 || cmd_time_out != NEVER) - pthread_create(&invoke_gdbserver_in_valgrind_thread, NULL, - invoke_gdbserver_in_valgrind, (void *) &pid); + pthread_create (&invoke_gdbserver_in_valgrind_thread, NULL, + invoke_gdbserver_in_valgrind, (void *) &pid); - to_pid = open_fifo(from_gdb_to_pid, O_WRONLY, "write to pid"); + to_pid = open_fifo (from_gdb_to_pid, O_WRONLY, "write to pid"); acquire_lock (shared_mem_fd, pid); /* first send a C-c \003 to pid, so that it wakes up the process @@ -963,111 +963,111 @@ void standalone_send_commands(int pid, At that point, we send our command and expect replies */ buf[0] = '\003'; i = 0; - while (!write_buf(to_pid, buf, 1, - "write \\003 to wake up", /* notify */ True)) { + while (!write_buf (to_pid, buf, 1, + "write \\003 to wake up", /* notify */ True)) { /* If write fails, retries up to 10 times every 0.5 seconds This aims at solving the race condition described in remote-utils.c remote_finish function. */ - usleep(500*1000); + usleep (500 * 1000); i++; if (i >= 10) XERROR (errno, "failed to send wake up char after 10 trials\n"); } - from_pid = open_fifo(to_gdb_from_pid, O_RDONLY, - "read cmd result from pid"); + from_pid = open_fifo (to_gdb_from_pid, O_RDONLY, + "read cmd result from pid"); /* Enable no ack mode. */ - write_buf(to_pid, "$QStartNoAckMode#b0", 19, "write start no ack mode", - /* notify */ True); - buflen = getpkt(buf, from_pid, to_pid); - if (buflen != 2 || strcmp(buf, "OK") != 0) { + write_buf (to_pid, "$QStartNoAckMode#b0", 19, "write start no ack mode", + /* notify */ True); + buflen = getpkt (buf, from_pid, to_pid); + if (buflen != 2 || strcmp (buf, "OK") != 0) { if (buflen != 2) ERROR (0, "no ack mode: unexpected buflen %d\n", buflen); else ERROR (0, "no ack mode: unexpected packet %s\n", buf); } - + for (nc = 0; nc <= last_command; nc++) { fprintf (stderr, "sending command %s to pid %d\n", commands[nc], pid); fflush (stderr); - + /* prepare hexcommand $qRcmd,xxxx....................xx#cc */ - hexcommand = vmalloc (packet_len_for_command(commands[nc])); + hexcommand = vmalloc (packet_len_for_command (commands[nc])); hexcommand[0] = 0; strcat (hexcommand, "$qRcmd,"); - for (i = 0; i < strlen(commands[nc]); i++) { - sprintf(hex, "%02x", (unsigned char) commands[nc][i]); + for (i = 0; i < strlen (commands[nc]); i++) { + sprintf (hex, "%02x", (unsigned char) commands[nc][i]); // Need to use unsigned char, to avoid sign extension. strcat (hexcommand, hex); } /* checksum (but without the $) */ cksum = 0; - for (hi = 1; hi < strlen(hexcommand); hi++) + for (hi = 1; hi < strlen (hexcommand); hi++) cksum+=hexcommand[hi]; - strcat(hexcommand, "#"); - sprintf(hex, "%02x", cksum); - strcat(hexcommand, hex); - write_buf(to_pid, hexcommand, strlen(hexcommand), - "writing hex command to pid", /* notify */ True); + strcat (hexcommand, "#"); + sprintf (hex, "%02x", cksum); + strcat (hexcommand, hex); + write_buf (to_pid, hexcommand, strlen (hexcommand), + "writing hex command to pid", /* notify */ True); /* we exit of the below loop explicitly when the command has been handled or because a signal handler will set shutting_down. */ while (!shutting_down) { - buflen = getpkt(buf, from_pid, to_pid); + buflen = getpkt (buf, from_pid, to_pid); if (buflen < 0) { ERROR (0, "error reading packet\n"); if (buflen == -2) - invoker_valgrind_dying(); + invoker_valgrind_dying (); break; } - if (strlen(buf) == 0) { - DEBUG(0, "empty packet rcvd (packet qRcmd not recognised?)\n"); + if (strlen (buf) == 0) { + DEBUG (0, "empty packet rcvd (packet qRcmd not recognised?)\n"); break; } - if (strcmp(buf, "OK") == 0) { - DEBUG(1, "OK packet rcvd\n"); + if (strcmp (buf, "OK") == 0) { + DEBUG (1, "OK packet rcvd\n"); break; } if (buf[0] == 'E') { - DEBUG(0, - "E NN error packet rcvd: %s (unknown monitor command?)\n", - buf); + DEBUG (0, + "E NN error packet rcvd: %s (unknown monitor command?)\n", + buf); break; } if (buf[0] == 'W') { - DEBUG(0, "W stopped packet rcvd: %s\n", buf); + DEBUG (0, "W stopped packet rcvd: %s\n", buf); break; } if (buf[0] == 'T') { - DEBUG(1, "T resume reply packet received: %s\n", buf); + DEBUG (1, "T resume reply packet received: %s\n", buf); continue; } - - /* must be here an O packet with hex encoded string reply + + /* must be here an O packet with hex encoded string reply => decode and print it */ if (buf[0] != 'O') { - DEBUG(0, "expecting O packet, received: %s\n", buf); + DEBUG (0, "expecting O packet, received: %s\n", buf); continue; } { char buf_print[buflen/2 + 1]; for (i = 1; i < buflen; i = i + 2) - buf_print[i/2] = (fromhex(*(buf+i)) << 4) - + fromhex(*(buf+i+1)); + buf_print[i/2] = (fromhex (*(buf+i)) << 4) + + fromhex (*(buf+i+1)); buf_print[buflen/2] = 0; - printf("%s", buf_print); - fflush(stdout); + printf ("%s", buf_print); + fflush (stdout); } } free (hexcommand); } shutting_down = True; - close_connection(to_pid, from_pid); + close_connection (to_pid, from_pid); } -/* report to user the existence of a vgdb-able valgrind process +/* report to user the existence of a vgdb-able valgrind process with given pid. Note: this function does not use XERROR if an error is encountered while producing the command line for pid, as this is not critical @@ -1079,14 +1079,14 @@ void report_pid (int pid, Bool on_stdout) int fd, i; FILE *out = on_stdout ? stdout : stderr; - fprintf(out, "use --pid=%d for ", pid); + fprintf (out, "use --pid=%d for ", pid); - sprintf(cmdline_file, "/proc/%d/cmdline", pid); + sprintf (cmdline_file, "/proc/%d/cmdline", pid); fd = open (cmdline_file, O_RDONLY); if (fd == -1) { - DEBUG(1, "error opening cmdline file %s %s\n", - cmdline_file, strerror(errno)); - fprintf(out, "(could not open process command line)\n"); + DEBUG (1, "error opening cmdline file %s %s\n", + cmdline_file, strerror (errno)); + fprintf (out, "(could not open process command line)\n"); } else { char cmdline[100]; ssize_t sz; @@ -1095,23 +1095,23 @@ void report_pid (int pid, Bool on_stdout) if (cmdline[i] == 0) cmdline[i] = ' '; cmdline[sz] = 0; - fprintf(out, "%s", cmdline); + fprintf (out, "%s", cmdline); } if (sz == -1) { - DEBUG(1, "error reading cmdline file %s %s\n", - cmdline_file, strerror(errno)); - fprintf(out, "(error reading process command line)"); + DEBUG (1, "error reading cmdline file %s %s\n", + cmdline_file, strerror (errno)); + fprintf (out, "(error reading process command line)"); } - fprintf(out, "\n"); + fprintf (out, "\n"); close (fd); - } - fflush(out); + } + fflush (out); } static -void usage(void) +void usage (void) { - fprintf(stderr, + fprintf (stderr, "Usage: vgdb [OPTION]... [[-c] COMMAND]...\n" "vgdb (valgrind gdb) has two usages\n" " 1. standalone to send monitor commands to a Valgrind gdbserver.\n" @@ -1143,9 +1143,9 @@ void usage(void) "\n" " -h --help shows this message\n" " To get help from the Valgrind gdbserver, use vgdb help\n" -"\n", vgdb_prefix_default() +"\n", vgdb_prefix_default () ); - invoker_restrictions_msg(); + invoker_restrictions_msg (); } /* If show_list, outputs on stdout the list of Valgrind processes with gdbserver activated. @@ -1161,7 +1161,7 @@ void usage(void) or exits in case of error (e.g. no pid found corresponding to arg_pid */ static -int search_arg_pid(int arg_pid, int check_trials, Bool show_list) +int search_arg_pid (int arg_pid, int check_trials, Bool show_list) { int i; int pid = -1; @@ -1170,7 +1170,7 @@ int search_arg_pid(int arg_pid, int check_trials, Bool show_list) fprintf (stderr, "vgdb error: invalid pid %d given\n", arg_pid); exit (1); } else { - /* search for a matching named fifo. + /* search for a matching named fifo. If we have been given a pid, we will check that the matching FIFO is there (or wait the nr of check_trials for this to appear). If no pid has been given, then if we find only one FIFO, @@ -1183,14 +1183,14 @@ int search_arg_pid(int arg_pid, int check_trials, Bool show_list) int is; int nr_valid_pid = 0; const char *suffix = "-from-vgdb-to-"; /* followed by pid */ - char *vgdb_format = vmalloc (strlen(vgdb_prefix) + strlen(suffix) + 1); - + char *vgdb_format = vmalloc (strlen (vgdb_prefix) + strlen (suffix) + 1); + strcpy (vgdb_format, vgdb_prefix); strcat (vgdb_format, suffix); - - if (strchr(vgdb_prefix, '/') != NULL) { + + if (strchr (vgdb_prefix, '/') != NULL) { strcpy (vgdb_dir_name, vgdb_prefix); - for (is = strlen(vgdb_prefix) - 1; is >= 0; is--) + for (is = strlen (vgdb_prefix) - 1; is >= 0; is--) if (vgdb_dir_name[is] == '/') { vgdb_dir_name[is+1] = '\0'; break; @@ -1199,8 +1199,8 @@ int search_arg_pid(int arg_pid, int check_trials, Bool show_list) strcpy (vgdb_dir_name, ""); } - DEBUG(1, "searching pid in directory %s format %s\n", - vgdb_dir_name, vgdb_format); + DEBUG (1, "searching pid in directory %s format %s\n", + vgdb_dir_name, vgdb_format); /* try to find FIFOs with valid pid. On exit of the loop, pid is set to: @@ -1210,38 +1210,38 @@ int search_arg_pid(int arg_pid, int check_trials, Bool show_list) otherwise it is set to the (only) pid found that can be debugged */ for (i = 0; i < check_trials; i++) { - DEBUG(1, "check_trial %d \n", i); + DEBUG (1, "check_trial %d \n", i); if (i > 0) /* wait one second before checking again */ - sleep(1); + sleep (1); vgdb_dir = opendir (strlen (vgdb_dir_name) ? vgdb_dir_name : "./"); if (vgdb_dir == NULL) - XERROR (errno, - "vgdb error: opening directory %s searching vgdb fifo\n", + XERROR (errno, + "vgdb error: opening directory %s searching vgdb fifo\n", vgdb_dir_name); - + errno = 0; /* avoid complain if vgdb_dir is empty */ while ((f = readdir (vgdb_dir))) { struct stat st; - char pathname[strlen(vgdb_dir_name) + strlen(f->d_name) + 1]; + char pathname[strlen (vgdb_dir_name) + strlen (f->d_name) + 1]; char *wrongpid; int newpid; strcpy (pathname, vgdb_dir_name); strcat (pathname, f->d_name); - DEBUG(3, "checking pathname is FIFO %s\n", pathname); + DEBUG (3, "checking pathname is FIFO %s\n", pathname); if (stat (pathname, &st) != 0) { if (debuglevel >= 3) - ERROR (errno, "vgdb error: stat %s searching vgdb fifo\n", + ERROR (errno, "vgdb error: stat %s searching vgdb fifo\n", pathname); } else if (S_ISFIFO (st.st_mode)) { - DEBUG(3, "trying FIFO %s\n", pathname); - if (strncmp (pathname, vgdb_format, + DEBUG (3, "trying FIFO %s\n", pathname); + if (strncmp (pathname, vgdb_format, strlen (vgdb_format)) == 0) { - newpid = strtol(pathname + strlen (vgdb_format), - &wrongpid, 10); - if (*wrongpid == '-' && newpid > 0 + newpid = strtol (pathname + strlen (vgdb_format), + &wrongpid, 10); + if (*wrongpid == '-' && newpid > 0 && kill (newpid, 0) == 0) { nr_valid_pid++; if (show_list) { @@ -1253,8 +1253,8 @@ int search_arg_pid(int arg_pid, int check_trials, Bool show_list) } } else if (nr_valid_pid > 1) { if (nr_valid_pid == 2) { - fprintf - (stderr, + fprintf + (stderr, "no --pid= arg given" " and multiple valgrind pids found:\n"); report_pid (pid, /*on_stdout*/ False); @@ -1270,7 +1270,7 @@ int search_arg_pid(int arg_pid, int check_trials, Bool show_list) errno = 0; /* avoid complain if at the end of vgdb_dir */ } if (f == NULL && errno != 0) - XERROR (errno, "vgdb error: reading directory %s for vgdb fifo\n", + XERROR (errno, "vgdb error: reading directory %s for vgdb fifo\n", vgdb_dir_name); closedir (vgdb_dir); @@ -1281,14 +1281,14 @@ int search_arg_pid(int arg_pid, int check_trials, Bool show_list) free (vgdb_dir_name); free (vgdb_format); } - + if (show_list) { exit (1); } else if (pid == -1) { if (arg_pid == -1) fprintf (stderr, "vgdb error: no FIFO found and no pid given\n"); else - fprintf (stderr, "vgdb error: no FIFO found matching pid %d\n", + fprintf (stderr, "vgdb error: no FIFO found matching pid %d\n", arg_pid); exit (1); } @@ -1301,21 +1301,21 @@ int search_arg_pid(int arg_pid, int check_trials, Bool show_list) } } -/* return true if the numeric value of an option of the +/* return true if the numeric value of an option of the form --xxxxxxxxx=<number> could properly be extracted from arg. If True is returned, *value contains the extracted value.*/ static -Bool numeric_val(char* arg, int *value) +Bool numeric_val (char* arg, int *value) { - const char *eq_pos = strchr(arg, '='); + const char *eq_pos = strchr (arg, '='); char *wrong; long long int long_value; if (eq_pos == NULL) return False; - long_value = strtoll(eq_pos+1, &wrong, 10); + long_value = strtoll (eq_pos+1, &wrong, 10); if (long_value < 0 || long_value > INT_MAX) return False; if (*wrong) @@ -1327,13 +1327,13 @@ Bool numeric_val(char* arg, int *value) /* true if arg matches the provided option */ static -Bool is_opt(char* arg, const char *option) +Bool is_opt (char* arg, const char *option) { - int option_len = strlen(option); + int option_len = strlen (option); if (option[option_len-1] == '=') - return (0 == strncmp(option, arg, option_len)); + return (0 == strncmp (option, arg, option_len)); else - return (0 == strcmp(option, arg)); + return (0 == strcmp (option, arg)); } /* Parse command lines options. If error(s), exits. @@ -1342,14 +1342,14 @@ Bool is_opt(char* arg, const char *option) On return, *p_last_command gives the position in commands where the last command has been allocated (using vmalloc). */ static -void parse_options(int argc, char** argv, - Bool *p_show_shared_mem, - Bool *p_show_list, - int *p_arg_pid, - int *p_check_trials, - int *p_port, - int *p_last_command, - char *commands[]) +void parse_options (int argc, char** argv, + Bool *p_show_shared_mem, + Bool *p_show_list, + int *p_arg_pid, + int *p_check_trials, + int *p_port, + int *p_last_command, + char *commands[]) { Bool show_shared_mem = False; Bool show_list = False; @@ -1362,18 +1362,18 @@ void parse_options(int argc, char** argv, int arg_errors = 0; for (i = 1; i < argc; i++) { - if (is_opt(argv[i], "--help") || is_opt(argv[i], "-h")) { - usage(); - exit(0); - } else if (is_opt(argv[i], "-d")) { + if (is_opt (argv[i], "--help") || is_opt (argv[i], "-h")) { + usage (); + exit (0); + } else if (is_opt (argv[i], "-d")) { debuglevel++; - } else if (is_opt(argv[i], "-D")) { + } else if (is_opt (argv[i], "-D")) { show_shared_mem = True; - } else if (is_opt(argv[i], "-l")) { + } else if (is_opt (argv[i], "-l")) { show_list = True; - } else if (is_opt(argv[i], "--pid=")) { + } else if (is_opt (argv[i], "--pid=")) { int newpid; - if (!numeric_val(argv[i], &newpid)) { + if (!numeric_val (argv[i], &newpid)) { fprintf (stderr, "invalid --pid argument %s\n", argv[i]); arg_errors++; } else if (arg_pid != -1) { @@ -1382,33 +1382,33 @@ void parse_options(int argc, char** argv, } else { arg_pid = newpid; } - } else if (is_opt(argv[i], "--wait=")) { - if (!numeric_val(argv[i], &check_trials)) { + } else if (is_opt (argv[i], "--wait=")) { + if (!numeric_val (argv[i], &check_trials)) { fprintf (stderr, "invalid --wait argument %s\n", argv[i]); arg_errors++; } - } else if (is_opt(argv[i], "--max-invoke-ms=")) { - if (!numeric_val(argv[i], &max_invoke_ms)) { + } else if (is_opt (argv[i], "--max-invoke-ms=")) { + if (!numeric_val (argv[i], &max_invoke_ms)) { fprintf (stderr, "invalid --max-invoke-ms argument %s\n", argv[i]); arg_errors++; } - } else if (is_opt(argv[i], "--cmd-time-out=")) { - if (!numeric_val(argv[i], &cmd_time_out)) { + } else if (is_opt (argv[i], "--cmd-time-out=")) { + if (!numeric_val (argv[i], &cmd_time_out)) { fprintf (stderr, "invalid --cmd-time-out argument %s\n", argv[i]); arg_errors++; } - } else if (is_opt(argv[i], "--port=")) { - if (!numeric_val(argv[i], &int_port)) { + } else if (is_opt (argv[i], "--port=")) { + if (!numeric_val (argv[i], &int_port)) { fprintf (stderr, "invalid --port argument %s\n", argv[i]); arg_errors++; } - } else if (is_opt(argv[i], "--vgdb-prefix=")) { + } else if (is_opt (argv[i], "--vgdb-prefix=")) { vgdb_prefix = argv[i] + 14; - } else if (is_opt(argv[i], "-c")) { + } else if (is_opt (argv[i], "-c")) { last_command++; commands[last_command] = vmalloc (1); commands[last_command][0] = '\0'; - } else if (0 == strncmp(argv[i], "-", 1)) { + } else if (0 == strncmp (argv[i], "-", 1)) { fprintf (stderr, "unknown or invalid argument %s\n", argv[i]); arg_errors++; } else { @@ -1419,30 +1419,30 @@ void parse_options(int argc, char** argv, commands[last_command] = vmalloc (1); commands[last_command][0] = '\0'; } - len = strlen(commands[last_command]); - commands[last_command] = vrealloc (commands[last_command], - len + 1 + strlen(argv[i]) + 1); + len = strlen (commands[last_command]); + commands[last_command] = vrealloc (commands[last_command], + len + 1 + strlen (argv[i]) + 1); if (len > 0) strcat (commands[last_command], " "); strcat (commands[last_command], argv[i]); - if (packet_len_for_command(commands[last_command]) > PBUFSIZ) { + if (packet_len_for_command (commands[last_command]) > PBUFSIZ) { fprintf (stderr, "command %s too long\n", commands[last_command]); arg_errors++; } - + } } if (vgdb_prefix == NULL) - vgdb_prefix = vgdb_prefix_default(); + vgdb_prefix = vgdb_prefix_default (); - if (isatty(0) - && !show_shared_mem + if (isatty (0) + && !show_shared_mem && !show_list && int_port == 0 && last_command == -1) { arg_errors++; - fprintf (stderr, + fprintf (stderr, "Using vgdb standalone implies to give -D or -l or a COMMAND\n"); } @@ -1452,7 +1452,7 @@ void parse_options(int argc, char** argv, "Can't use both -D and -l options\n"); } - if (max_invoke_ms > 0 + if (max_invoke_ms > 0 && cmd_time_out != NEVER && (cmd_time_out * 1000) <= max_invoke_ms) { arg_errors++; @@ -1474,7 +1474,7 @@ void parse_options(int argc, char** argv, if (arg_errors > 0) { fprintf (stderr, "args error. Try `vgdb --help` for more information\n"); - exit(1); + exit (1); } *p_show_shared_mem = show_shared_mem; @@ -1485,7 +1485,7 @@ void parse_options(int argc, char** argv, *p_last_command = last_command; } -int main(int argc, char** argv) +int main (int argc, char** argv) { int i; int pid; @@ -1498,48 +1498,48 @@ int main(int argc, char** argv) int last_command; char *commands[argc]; // we will never have more commands than args. - parse_options(argc, argv, - &show_shared_mem, - &show_list, - &arg_pid, - &check_trials, - &in_port, - &last_command, - commands); - + parse_options (argc, argv, + &show_shared_mem, + &show_list, + &arg_pid, + &check_trials, + &in_port, + &last_command, + commands); + /* when we are working as a relay for gdb, handle some signals by only reporting them (according to debug level). Also handle these when ptrace will be used: vgdb must clean up the ptrace effect before dying. */ if (max_invoke_ms > 0 || last_command == -1) - install_handlers(); + install_handlers (); pid = search_arg_pid (arg_pid, check_trials, show_list); - prepare_fifos_and_shared_mem(pid); + prepare_fifos_and_shared_mem (pid); if (in_port > 0) - wait_for_gdb_connect(in_port); + wait_for_gdb_connect (in_port); if (show_shared_mem) { - fprintf(stderr, - "vgdb %d " - "written_by_vgdb %d " - "seen_by_valgrind %d\n" - "vgdb pid %d\n", - VS_vgdb_pid, - VS_written_by_vgdb, - VS_seen_by_valgrind, - VS_vgdb_pid); + fprintf (stderr, + "vgdb %d " + "written_by_vgdb %d " + "seen_by_valgrind %d\n" + "vgdb pid %d\n", + VS_vgdb_pid, + VS_written_by_vgdb, + VS_seen_by_valgrind, + VS_vgdb_pid); exit (0); } if (last_command >= 0) { - standalone_send_commands(pid, last_command, commands); + standalone_send_commands (pid, last_command, commands); } else { - gdb_relay(pid); + gdb_relay (pid); } - + free (from_gdb_to_pid); free (to_gdb_from_pid); |