From patchwork Fri Nov 17 16:26:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 24314 Received: (qmail 20113 invoked by alias); 17 Nov 2017 16:27:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 20060 invoked by uid 89); 17 Nov 2017 16:27:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KB_WAM_FROM_NAME_SINGLEWORD, SPF_PASS autolearn=ham version=3.3.2 spammy=destroys X-HELO: sessmg22.ericsson.net Received: from sessmg22.ericsson.net (HELO sessmg22.ericsson.net) (193.180.251.58) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 17 Nov 2017 16:27:19 +0000 Received: from ESESSHC020.ericsson.se (Unknown_Domain [153.88.183.78]) by sessmg22.ericsson.net (Symantec Mail Security) with SMTP id 14.EE.19528.4ED0F0A5; Fri, 17 Nov 2017 17:27:16 +0100 (CET) Received: from EUR03-VE1-obe.outbound.protection.outlook.com (153.88.183.145) by oa.msg.ericsson.com (153.88.183.78) with Microsoft SMTP Server (TLS) id 14.3.352.0; Fri, 17 Nov 2017 17:27:15 +0100 Received: from elxacz23q12.ca.am.ericsson.se (192.75.88.130) by AMSPR07MB309.eurprd07.prod.outlook.com (2a01:111:e400:802f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.239.4; Fri, 17 Nov 2017 16:27:14 +0000 From: Simon Marchi To: CC: Simon Marchi Subject: [PATCH 3/4] Make process_info::syscalls_to_catch an std::vector Date: Fri, 17 Nov 2017 11:26:48 -0500 Message-ID: <1510936009-12779-4-git-send-email-simon.marchi@ericsson.com> In-Reply-To: <1510936009-12779-1-git-send-email-simon.marchi@ericsson.com> References: <1510936009-12779-1-git-send-email-simon.marchi@ericsson.com> MIME-Version: 1.0 X-ClientProxiedBy: SN2PR01CA0028.prod.exchangelabs.com (2603:10b6:804:2::38) To AMSPR07MB309.eurprd07.prod.outlook.com (2a01:111:e400:802f::12) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a6b78825-3862-4f4b-6725-08d52dd8101a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603258); SRVR:AMSPR07MB309; X-Microsoft-Exchange-Diagnostics: 1; AMSPR07MB309; 3:wD+Zs38BClgvFaB7u+fIpAlI8aaQEymHvbgIbJmJfSpwO/GvPvnaeyXsW3hEzk996THtSs72e4R0/uw/3rBYDOTz1xPSsG4VrVwvfHJb5/jh3JbdPXfX37vCRz0FPttmyyP4Vfb0hBPBOKbyniAhasSIbzugqJKBkK5zV+soZbxi8O827qx6yqzaVl7t1J63LMBz6sHFCVKqKyC3rRbq4vfHSd0CpbK6Ecav6K0mGbuQReP4KuH8A89LnAPH/4tb; 25:7SW9HsUPahehKpWIHIRi6VGLb4L7fbu2SVdmB99u6McWCP9GoKclFuPD44y2SsWX+ok76lYiA5yJ7iiASIHfpi96NXeSfmgD9IhWykuk874cXx9M35M9axY27306l9JB6j5LNY/ZEv9qo8rpo76hlUb1D6iynM82KrjEaGrwH80+aONmwMP/glFKPX+pwPTjdt6OEJRr7sgtI5n1iKaH4X9HyzHk/M5Wt044JxxqAud5DVWhGaxk6s0Ste42Rht28XMQ+9xNgWMxYfr9PZNd7CrU7k2+ReAJXxbZz/zkBhjCW1RpGgOw8L/xlVy1/2PCroOT9pg00YouYdsMYCBw025giwcmA5QeTnSVp5fbqC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D1MPCzMCBZnkR4ErmHXfpBAzG3w== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(10201501046)(3231022)(100000703101)(100105400095)(93006095)(93001095)(3002001)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123562025)(20161123560025)(20161123564025)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AMSPR07MB309; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AMSPR07MB309; X-Forefront-PRVS: 049486C505 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(346002)(376002)(54534003)(189002)(199003)(305945005)(6506006)(189998001)(50226002)(7736002)(4326008)(6116002)(33646002)(3846002)(2906002)(6512007)(86362001)(16586007)(6916009)(53936002)(2950100002)(97736004)(5660300001)(316002)(2361001)(575784001)(6666003)(106356001)(50466002)(48376002)(81156014)(8676002)(5003940100001)(68736007)(25786009)(81166006)(47776003)(6486002)(16526018)(8936002)(66066001)(478600001)(36756003)(101416001)(2351001)(50986999)(76176999)(5890100001)(105586002); DIR:OUT; SFP:1101; SCL:1; SRVR:AMSPR07MB309; H:elxacz23q12.ca.am.ericsson.se; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AMSPR07MB309; 23:ymdZPcQXjKJnPvyZbVjMrQRS90WduwSbfHRSrPN/iT?= =?us-ascii?Q?E9YutWOtcDt5Qb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Vf1xRp74oYMtZThK6LA/vlUYE3KVAJCcnGyzpac1NZZxRTqfRsC0ZZn4hJpIv6IrS/BrWCqYiNd7iTgbV7OZNd77Z8I7wPeajSEXQfpTLM8+26ASiWHzlchNgRT4U4Ww+dsR5UU+2SMvrZcORxq4mSnSZSBkLNqoljTHaW3TAQYTWUfoX6a2OvAFUb8jhtdQJfEH7hMtMxD SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2017 16:27:14.1019 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a6b78825-3862-4f4b-6725-08d52dd8101a X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AMSPR07MB309 X-OriginatorOrg: ericsson.com X-IsSubscribed: yes From: Simon Marchi This patch makes the syscalls_to_catch field of process_info an std::vector. The process_info structure must now be newed/deleted. In handle_extended_wait, the code that handles exec events destroys the existing process_info and creates a new one. It moves the content of syscalls_to_catch from the old to the new vector. I used std::move for that (through an intermediary variable), which should have the same behavior as the old code. gdb/gdbserver/ChangeLog: * inferiors.h (struct process_info): Add constructor, initialize fields.. : Change type to std::vector. * inferiors.c (add_process): Allocate process_info with new. (remove_process): Free process_info with delete. * linux-low.c (handle_extended_wait): Adjust. (gdb_catching_syscalls_p, gdb_catch_this_syscall_p): Adjust. * server.c (handle_general_set): Adjust. --- gdb/gdbserver/inferiors.c | 8 ++------ gdb/gdbserver/inferiors.h | 20 ++++++++++++-------- gdb/gdbserver/linux-low.c | 19 ++++++++----------- gdb/gdbserver/server.c | 6 +++--- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c index a0ece4d..f4101c7 100644 --- a/gdb/gdbserver/inferiors.c +++ b/gdb/gdbserver/inferiors.c @@ -194,10 +194,7 @@ clear_inferiors (void) struct process_info * add_process (int pid, int attached) { - struct process_info *process = XCNEW (struct process_info); - - process->pid = pid; - process->attached = attached; + process_info *process = new process_info (pid, attached); all_processes.push_back (process); @@ -215,8 +212,7 @@ remove_process (struct process_info *process) free_all_breakpoints (process); gdb_assert (find_thread_process (process) == NULL); all_processes.remove (process); - VEC_free (int, process->syscalls_to_catch); - free (process); + delete process; } process_info * diff --git a/gdb/gdbserver/inferiors.h b/gdb/gdbserver/inferiors.h index fb0e2fd..4c66a74 100644 --- a/gdb/gdbserver/inferiors.h +++ b/gdb/gdbserver/inferiors.h @@ -33,6 +33,10 @@ struct process_info_private; struct process_info { + process_info (int pid_, int attached_) + : pid (pid_), attached (attached_) + {} + /* This process' pid. */ int pid; @@ -42,28 +46,28 @@ struct process_info /* True if GDB asked us to detach from this process, but we remained attached anyway. */ - int gdb_detached; + int gdb_detached = 0; /* The symbol cache. */ - struct sym_cache *symbol_cache; + struct sym_cache *symbol_cache = NULL; /* The list of memory breakpoints. */ - struct breakpoint *breakpoints; + struct breakpoint *breakpoints = NULL; /* The list of raw memory breakpoints. */ - struct raw_breakpoint *raw_breakpoints; + struct raw_breakpoint *raw_breakpoints = NULL; /* The list of installed fast tracepoints. */ - struct fast_tracepoint_jump *fast_tracepoint_jumps; + struct fast_tracepoint_jump *fast_tracepoint_jumps = NULL; /* The list of syscalls to report, or just a single element, ANY_SYSCALL, for unfiltered syscall reporting. */ - VEC (int) *syscalls_to_catch; + std::vector syscalls_to_catch; - const struct target_desc *tdesc; + const struct target_desc *tdesc = NULL; /* Private target data. */ - struct process_info_private *priv; + struct process_info_private *priv = NULL; }; /* Get the pid of PROC. */ diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index b367e53..b267c70 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -683,7 +683,7 @@ handle_extended_wait (struct lwp_info **orig_event_lwp, int wstat) else if (event == PTRACE_EVENT_EXEC && report_exec_events) { struct process_info *proc; - VEC (int) *syscalls_to_catch; + std::vector syscalls_to_catch; ptid_t event_ptid; pid_t event_pid; @@ -699,8 +699,7 @@ handle_extended_wait (struct lwp_info **orig_event_lwp, int wstat) /* Save the syscall list from the execing process. */ proc = get_thread_process (event_thr); - syscalls_to_catch = proc->syscalls_to_catch; - proc->syscalls_to_catch = NULL; + syscalls_to_catch = std::move (proc->syscalls_to_catch); /* Delete the execing process and all its threads. */ linux_mourn (proc); @@ -731,7 +730,7 @@ handle_extended_wait (struct lwp_info **orig_event_lwp, int wstat) /* Restore the list to catch. Don't rely on the client, which is free to avoid sending a new list when the architecture doesn't change. Also, for ANY_SYSCALL, the architecture doesn't really matter. */ - proc->syscalls_to_catch = syscalls_to_catch; + proc->syscalls_to_catch = std::move (syscalls_to_catch); /* Report the event. */ *orig_event_lwp = event_lwp; @@ -3182,7 +3181,7 @@ gdb_catching_syscalls_p (struct lwp_info *event_child) struct thread_info *thread = get_lwp_thread (event_child); struct process_info *proc = get_thread_process (thread); - return !VEC_empty (int, proc->syscalls_to_catch); + return !proc->syscalls_to_catch.empty (); } /* Returns 1 if GDB is interested in the event_child syscall. @@ -3191,21 +3190,19 @@ gdb_catching_syscalls_p (struct lwp_info *event_child) static int gdb_catch_this_syscall_p (struct lwp_info *event_child) { - int i, iter; int sysno; struct thread_info *thread = get_lwp_thread (event_child); struct process_info *proc = get_thread_process (thread); - if (VEC_empty (int, proc->syscalls_to_catch)) + if (proc->syscalls_to_catch.empty ()) return 0; - if (VEC_index (int, proc->syscalls_to_catch, 0) == ANY_SYSCALL) + if (proc->syscalls_to_catch[0] == ANY_SYSCALL) return 1; get_syscall_trapinfo (event_child, &sysno); - for (i = 0; - VEC_iterate (int, proc->syscalls_to_catch, i, iter); - i++) + + for (int iter : proc->syscalls_to_catch) if (iter == sysno) return 1; diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index e827b9c..f0dac95 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -623,7 +623,7 @@ handle_general_set (char *own_buf) } process = current_process (); - VEC_truncate (int, process->syscalls_to_catch, 0); + process->syscalls_to_catch.clear (); if (enabled) { @@ -634,11 +634,11 @@ handle_general_set (char *own_buf) while (*p != '\0') { p = decode_address_to_semicolon (&sysno, p); - VEC_safe_push (int, process->syscalls_to_catch, (int) sysno); + process->syscalls_to_catch.push_back (sysno); } } else - VEC_safe_push (int, process->syscalls_to_catch, ANY_SYSCALL); + process->syscalls_to_catch.push_back (ANY_SYSCALL); } write_ok (own_buf);