From patchwork Wed Nov 30 16:02:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 18068 Received: (qmail 54740 invoked by alias); 30 Nov 2016 16:04:46 -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 54725 invoked by uid 89); 30 Nov 2016 16:04:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 spammy=Background, 83416, remotely, Consume X-HELO: sesbmg23.ericsson.net Received: from sesbmg23.ericsson.net (HELO sesbmg23.ericsson.net) (193.180.251.37) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 30 Nov 2016 16:04:34 +0000 Received: from ESESSHC002.ericsson.se (Unknown_Domain [153.88.183.24]) by (Symantec Mail Security) with SMTP id DF.79.32482.828FE385; Wed, 30 Nov 2016 17:02:49 +0100 (CET) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (153.88.183.145) by oa.msg.ericsson.com (153.88.183.24) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 30 Nov 2016 17:02:48 +0100 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; Received: from [142.133.49.242] (192.75.88.130) by DB4PR07MB394.eurprd07.prod.outlook.com (10.141.236.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.761.5; Wed, 30 Nov 2016 16:02:44 +0000 Subject: Re: [PATCH] Prevent turning record on while threads are running (PR 20869) To: "Metzger, Markus T" , "gdb-patches@sourceware.org" References: <20161129150758.29912-1-simon.marchi@ericsson.com> From: Simon Marchi Message-ID: <9eb04d8f-641a-3c2f-53e2-ed4ecf7ab810@ericsson.com> Date: Wed, 30 Nov 2016 11:02:35 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: X-ClientProxiedBy: BN3PR16CA0046.namprd16.prod.outlook.com (10.165.72.142) To DB4PR07MB394.eurprd07.prod.outlook.com (10.141.236.17) X-MS-Office365-Filtering-Correlation-Id: 33635795-f89e-4a75-730f-08d4193a5298 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DB4PR07MB394; X-Microsoft-Exchange-Diagnostics: 1; DB4PR07MB394; 3:mj1F30wWPteKh/tT9iAyQs6Nga9HvE6Rhz8Dy+zvAphVGFQMvxpRjATPM5zv3Pim22EATdXp8vhpv1kj7+II3FQhtK8Rm6uK5j4kKLfV8K/thfcRqe2G6HghwLmaQnD0NovpKOjJI1szLmhQezVbX2B3TabC1JFp6qOcHVYT1CZWNgBrqEq5jQ4Cj6DMC4WNYwPaQWbwHPvMWMrIW1UpDLgTsY8L6dUhjtbi5JE4ExXQC4cOoHUTQP5DheBm5BCCRBBQsI/k2nUEmqWFXDACfQ==; 25:kAJANgccN51XUAjVzlDAd0A9Yj4M5BGJw7Kr3Jbl0jRw2X7jeK2GfsOeBDi4AD3ugmlNnGPUxgvAEo83PRat3oUGARVBdeCl8QdTsIDTWPxTh4L9S4DfxhHYvMVteW/LlXcq9y4xKZC7LbAZoypMaICEjcOszvTozMt0HIxFJQm96oMKkDwKzGhOAhlIFG02ypiK5oWNn3KPzASz0BVbKzSxuj3rKY5UmxShTDDKikW596RvAMlPrEtO11Wx51RTj6PcHWC8DoL9Xy2QjI9Mv9hQr7Hp4oqJCvAje6jVehTUaE4u1KDiDax2A2LXhKFekkfIXhFizjNZIHUefCezb8OSSvrgetj/t9zdHhXlh2DoeWqYOM0f6nCME4zdWJiq651KSWcyTCazY1fif7yfvI7zrvHUO707Q07yO2fH3BrcKAG5iLFl44I1SZxjFSN5+16zlxOLJ0olJJ28RcBeZg== X-Microsoft-Exchange-Diagnostics: 1; DB4PR07MB394; 31:Tej3ZPicDN9qwiUM9heIhjlZu3Y9OWEedW0A4JJYzopd+W9YvG9+QITYz0iliNspf6A+bdkz7KfFG8RNXNVWCU/3X8Cfx9830x616llOGfuZ18Ys3HNE1TlzysPTvPtAtAK/K0F3UYejDZ3FUXkWxiBqhy2gkqRvjSAhQ9aQsI9lc8nX96EaN5vJGRJQIkI8tgNxSWyOfNjpW7TYT7HRYbEyLguwtO8CnTSPK50APOlEK8OTkvMq2CN4DuGPVzHWqFPOiWtXkDEBbSs5kkkbDAPOqO6Fkx0q4oyArmSFXFU=; 20:LWOL2keHuHKa5ahKobE1Rtp/0x+Wh2ZLjZFv1krFasbHNJMfBAUm4mpWXSa1phA+QRlSqXtN9z3MbrLWWv64ONqBUi6I8hIGR9hKEbGqIq6mkzivqzHyUreJHWrbW52coadPyBcPi/Bqhoqs86JrOS47Y1OwGiawe6vAfTum1IwkOmnyO6e6jL986EtoQctUIAecIXkd2yzb2CUkVFXIXe4b/yXuzGinFTI0Jj3PgW/vS9JaIaLMTXHp0fFnmlwke+yFGMsVbhymZOHhNPd0eejFKt9l+InnqOoBwIONOUahMre2AEw+pR3Z9SlPlDhRZGxilyzP05pX47EPLwCaCGxqngh+0PmNhgfHnjHmUtn9CPVk8ogBJgAA2cybyPyvQzFamQBg/ls0OJOcTrcRaKJkwMPpXs7MKXFoOKB2AHOnzQSLSXiYwInvBT9jzSeq1QCPX8E/nkcSl3gygUsKfQuPwgExMhC9cYK46uCwEB80u5v6+izgnXrfT3/RUKOs X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(37575265505322)(250305191791016)(22074186197030)(166708455590820)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6041248)(20161123562025)(20161123560025)(20161123555025)(20161123564025)(6072148); SRVR:DB4PR07MB394; BCL:0; PCL:0; RULEID:; SRVR:DB4PR07MB394; X-Microsoft-Exchange-Diagnostics: 1; DB4PR07MB394; 4:1zZdgSlwKu3pTcC97vRKdwzg6V/Y89MsWp5dFmBnWR07hcAwUiJv8lKM0FZIc3NfQjArLOZeG82SsJSDpDd80RwcdIAwcRmhVSPIzrIV4fL5+tmha/iQFkkGDqC1Aj0tk2bySoDaBOtxuPHm54WbFFU1Iwu9Ds6X2Stnh/qm9eZlZ7gK6CTsX+Sl87/F9Lu2TYY+ItjHQ+/WtHniK9YCrJc7fN7iZjf2JXnKNd+6A8xtNU+xZTWqanlhRXktbH3TbSycAL892Yd959qoDc7B3k3UPhU84TbpPf6FqCak+RivBI6EXDvqN4p2esPl813x+cI6ANQNcjZsp+7uCt/l/aA2+wI1Xub6gncPeDnjB6xo3WNLEm6teAXoo0i/44HFCuFzpJnUBG5uqXQcNQr7h/N0fx0Ebq+KiGv9MirUagiLP4tKDyXujWNB8E31P7btIMyYknMBra2r1p9hCG7jY0RHCsr7iCKU8vnV5dCKntx+UDgBdei+3I9FUzf/jTSXpPvL94bFtRgtReRA60aK9qJ6IZZskEC+IgLTD1HXSrwA0hMp/LpzxXHlmI8q3rbh1zMTMvFbcttnbEXqRNKGHHQibd8ZptHre2cCtBZYLX8L8I/jHISHWhvVzUTlLCABRl4Y01cpTHF82wZXpNfeWyYbtF6JGaTvX7phe1Kh0soYjZoA5MUSbGNcD2uHVUEibfo8kjC4z4006wHXQFW8wLHbUcad09bw9zAWnePgOF6EYfqmo+t6zUfiHoEzs5Hd X-Forefront-PRVS: 0142F22657 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6049001)(6009001)(7916002)(377424004)(54534003)(13464003)(24454002)(288314003)(51914003)(199003)(377454003)(189002)(65826007)(83506001)(6666003)(33646002)(305945005)(86362001)(65806001)(66066001)(107886002)(65956001)(733004)(47776003)(4001350100001)(8676002)(50466002)(5001770100001)(229853002)(39450400002)(97736004)(2950100002)(23746002)(36756003)(39410400001)(81156014)(38730400001)(81166006)(6486002)(7846002)(2501003)(6116002)(5660300001)(3846002)(50986999)(106356001)(7736002)(31696002)(189998001)(92566002)(31686004)(2906002)(54356999)(76176999)(230700001)(101416001)(42186005)(64126003)(105586002)(68736007)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB4PR07MB394; H:[142.133.49.242]; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1; DB4PR07MB394; 23:x7P7pGMyn3wPXzUIbe5WKSmC1JokVVZOwsRo5K?= =?Windows-1252?Q?18KFMgYTFbdDqixvQfVhNFcZIOjsBwrMD5un3KapObGOJ2NDpgz6zcGf?= =?Windows-1252?Q?wY3IrK9ui9uqXmZeXY/l2Ukf9VjCpqMB32MSQqtuytXx3UDCj1tRdwll?= =?Windows-1252?Q?d5wK15tm2bvZsgWujWm8VbWPf4LdDZCrM5IruDx81NJr8NKgeD7r2wNU?= =?Windows-1252?Q?PvvkPgbymNQqXhMh+TRinuUVDUcLrNlLYWuXXwVY6yCBVYdom4uJ8YRB?= =?Windows-1252?Q?XmvY4Fol+4qZwKzyt5ngyIHYk3UxfzzstQZl92ZGrj5u34crC+BTlZ0j?= =?Windows-1252?Q?7D5dkjplyGLrZTuiJzxCsTK0REhn5zCfsvJcA6dF6pc1UzyncozBWud0?= =?Windows-1252?Q?TzePRn3AKbtx8klBSpux55MeBYYgveHM8q+xqEp2DYLoX+V4PtPD0Dm1?= =?Windows-1252?Q?hNTAXMpS/MbTTkhjmP2JRuDrBpI94UbBaeU9UsoKq6QJbsgr+kDkxdGx?= =?Windows-1252?Q?OlgAHp3VHPQZogfg1oVnsLAbfz70a480rI7/V4x+cz0voSwPk4IRo32a?= =?Windows-1252?Q?/oO5txurmKd7BHC/wRFIARktIIiQmkI6eZoRv4hqH4KsAqTXneXnolDP?= =?Windows-1252?Q?Vs63f6wns2NGBtAknAGJfwzVsfzE3bIavvHRkbCq+w1Z6azL1kXN2V+T?= =?Windows-1252?Q?MXcZ0rAT+bpAxQrPiusgbvp3oC2XmvWkxYP73ni/UHl9YvRZJUfE6VPG?= =?Windows-1252?Q?b7BE9r2ohCQGL5w/JaRILKgXvm15ygs8PBe08ObkdUjA/VkxVbq5hh5M?= =?Windows-1252?Q?eBdO6fXmmiHQzKf0UocOmVLkzyV86kp0DWJDc/267gbLCiESNoHaUX2K?= =?Windows-1252?Q?jeQyE7A9bfppJfclBxxGpfrCch7HT+SaI0ieSIA7364twBfRyHO+6B2Y?= =?Windows-1252?Q?YkohGOCUuHBaYV5wGLcmuBZjbDTw7pU82eSANteEfYnB9C1BhcxILhr5?= =?Windows-1252?Q?4jcRxZ5EAxVf3aWFnS9IV9WO2I8EUu5ta0yRN9Nj6Xv6GzGSqDKkwRV7?= =?Windows-1252?Q?AdZAO8W9dmrAK/B82bK67WdYpi9gjnHQb9LWdgOgQIyOmXsT5jsFu0kn?= =?Windows-1252?Q?EdOvNyHbjBknYvP4fGHuFVOhnkLva4YToRbNp1mLtpsqM+IyLaUBYLm1?= =?Windows-1252?Q?3t0BMzvJrAHB6x3zoye+0beG4vWKF0n6GeAyRX7TJj1ePRaTO9dRQmy6?= =?Windows-1252?Q?u+LNp3MHusABbHJajcw9Ym/u8AYzTJHcdSdJHTy9zEx/6SXMwuZHbjQJ?= =?Windows-1252?Q?t4eOs1FqCuRoR13C9S5ounbQcgazWgEdx2EXNlkhmrqmIz2NPHZ5hPZV?= =?Windows-1252?Q?R8NEvzGi6NPVaGlet8cvbYkJzPB4g73G5yvRgJI7Y9kxpNF5eymzrHVg?= =?Windows-1252?Q?WPazd8PESu2leXhsnO/YXgnYlbxCnhuOMa22IS5PL99JEK/D2kaB1OSI?= =?Windows-1252?Q?P8SLjuCcANJOBHHlxY5bGrY2xx7dtVoD8/RN9WlwwQaS1OoSQAhBNkPb?= =?Windows-1252?Q?cRg0FqZPAWcYukBbmjNUIKCMdl4YYNkgmxfbBqK7JptuxCjBtAvD67GQ?= =?Windows-1252?Q?=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; DB4PR07MB394; 6:Q+q1he9YrAknsKk9ZqvKrDvVVkFHaDrhH5RUVeGg7NZXBS4Y+uix+VQSNGdQJ9WLl2YruKj8PHP5OcNiiRGj6y4m/K2jq9VKA3vvYRcQvoSk6YkDiTdCum+FCp2kEbhfnsrsrY0gchCxWw9aPq1TPGQDbxiK7Od64n08meeEyqGNlevYRK14yJgaT/vMNkKuUJx6ikRI/VCUmJN+KGhUv27X5NdYUn63CGwexrMQnAI6QSVW00MSUJEexBRzN1xR7BOCC1A+iduhZ3lqoninnv6euRDo6/5wDxiuXjGUtZlU6VaNzQXy+J3bUoG5ce8bhqyMajYETPM0OZk3NE8fEgJAoIOkkWU5ZK1ORQfbdNN7/utcPyZEA9Ck+oXjUSvCFnZJj2JEfua89DYG3U8GvI/1cnOgbqN1ArBjmNQM0CMmfsbZQ6zGKy7yO1YY6YNHOLWmT96QtkZ32ebP4lUOsQ==; 5:Y5mGhzKc0A/iSuButbFNi+dOWU8mP+qKdjmQgISXHHEoqnEFbzWAU8EK7kwsty+fNPbOfzyQ89VgwO6sjYPszP0BPIEIVdH7Aqn+JW24jCTGXGaDAR1u7/auoLD+I3QFqHwsVkezpohgEDHVe5qA9UGW0msRxMKWRjcHnyF3Dh8=; 24:g7LLU54gmRCrot75xWdRRgwWdsDrx/XRJ/BYeGjCmG32dJlmdzWXxUp5m80gi1aexWxk7Q161Lgcu3hPiniz+DVvg7erlnOeAx/BJTcBknU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB4PR07MB394; 7:bCmnufE73Lf0BeagH+U2ihGEgSuywceDtrMG+MX5Y8qS9oiv18M4UyZqJt2dxHM5Mivpmbk4YXqqHh/XYfaVZ3NEs+xE8swbeqvtMKlFGFLkVH+xy5hye05bHIaq08BaWHe+FjnSbNCuV5roaPyGeBNZEftkTvIX6fkE5i4GbgDAZgWUXnTWbBlQ3G5O/3hDWXpOeTvFRD1qoi2xMyTtsY2iO+MmYG9t02YTDOdROMhPWhZyES8FVD++W9kAb89s/10BOEM8960jA8Dac/YwMhqcPduEE0N7Npfhiqy4G+C13ue45Q2EvwhdOHHrGk0NkTr2UR/Ag9DzGvUJntJOTRwmdndOeTxTZQyFyw7s1d6ThuP7l0wkw1aZzfLWJYxa+TNXeSyvXgtKRmoIMcYDkp5iiUp/FSblVjqDKi19NiryJwqmjHDW1C0shBgxQk505Z4gBUASmNMG7q3soTRlMw== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2016 16:02:44.5588 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR07MB394 X-OriginatorOrg: ericsson.com X-IsSubscribed: yes On 16-11-30 04:54 AM, Metzger, Markus T wrote: >> -----Original Message----- >> From: Simon Marchi [mailto:simon.marchi@ericsson.com] >> Sent: Tuesday, November 29, 2016 4:08 PM >> To: gdb-patches@sourceware.org >> Cc: Metzger, Markus T ; Simon Marchi >> >> Subject: [PATCH] Prevent turning record on while threads are running (PR 20869) > > Hi Simon, > > Thanks for looking into this. > >> I also wanted to know whether it was supported to start btrace bts/pt >> recording with threads running. When I try it with btrace bts, it works >> halfway. "record btrace bts" gives me the error: >> >> Couldn't get registers: No such process. >> >> If I do the command again, gdb doesn't complain and then I'm able to >> interrupt the target and use reverse-next. However, since the >> initialization function was interrupted halfway, I am not sure that >> everything is setup correctly. If we want to allow it, we would first >> need to look into this issue. > > The issue with record-btrace is that tracing can be enabled on the target also for > running threads. When we try to insert the first record for the current PC so the > trace starts at the location from where we disabled tracing, regcache_read_pc > throws the above error. Since record_btrace_open has not installed a cleanup > to disable tracing again for this thread, we leave it enabled. > > (gdb) rec bts > [record-btrace] open > [btrace] enable thread 1 (Thread 0x7ffff7fcd740 (LWP 110345)) > [btrace] compute ftrace > [btrace] enable thread 2 (Thread 0x7ffff77fd700 (LWP 110346)) > [btrace] disable thread 1 (Thread 0x7ffff7fcd740 (LWP 110345)) > [btrace] clear thread 1 (Thread 0x7ffff7fcd740 (LWP 110345)) > Couldn't get registers: No such process. > > The next time we try to enable tracing, that running thread is already traced so > we skip it. If we have more than two threads running, we disable tracing again > on this thread when we fail on the next running thread. But we always leave the > highest-number running thread traced. > > (gdb) > [record-btrace] open > [btrace] enable thread 1 (Thread 0x7ffff7fcd740 (LWP 110345)) > [btrace] compute ftrace > [btrace] enable thread 4 (Thread 0x7ffff67fb700 (LWP 110348)) > [btrace] disable thread 3 (Thread 0x7ffff6ffc700 (LWP 110347)) > [btrace] clear thread 3 (Thread 0x7ffff6ffc700 (LWP 110347)) > [btrace] disable thread 2 (Thread 0x7ffff77fd700 (LWP 110346)) > [btrace] clear thread 2 (Thread 0x7ffff77fd700 (LWP 110346)) > [btrace] disable thread 1 (Thread 0x7ffff7fcd740 (LWP 110345)) > [btrace] clear thread 1 (Thread 0x7ffff7fcd740 (LWP 110345)) > Couldn't get registers: No such process. > > Eventually, all running threads are already traced and we succeed to enable tracing. > > The trace for running threads will start from their next branch target instead of from their > current position (for BTS). This shouldn't matter unless the thread was actually waiting > and not executing any code when we started tracing. We should be able to allow it like > this: > > diff --git a/gdb/btrace.c b/gdb/btrace.c > index 39d537c..b005627 100644 > --- a/gdb/btrace.c > +++ b/gdb/btrace.c > @@ -1474,8 +1474,28 @@ btrace_enable (struct thread_info *tp, const struct btrace_config *conf) > > /* Add an entry for the current PC so we start tracing from where we > enabled it. */ > - if (tp->btrace.target != NULL) > - btrace_add_pc (tp); > + TRY > + { > + if (tp->btrace.target != NULL) > + btrace_add_pc (tp); > + } > + CATCH (error, RETURN_MASK_ERROR) > + { > + /* We may fail to add the initial entry, for example if TP is currently > + running. > + > + For BTRACE_FORMAT_PT this doesn't matter. > + > + For BTRACE_FORMAT_BTS we won't be able to stitch the initial trace > + chunk to this initial entry so tracing will start at the next branch > + target instead of at the current PC. Since TP is currently running, > + this shouldn't make a difference. > + > + If TP were waiting most of the time and made only a little bit of > + progress before it was stopped, we'd lose the instructions until the > + first branch. */ > + } > + END_CATCH > } > > /* See btrace.h. */ > > Do you want to extend your patch to allow tracing to be enabled for btrace or > would you rather have me fix this on top of your patch? Hi Markus, Thanks for the quick response, I can confirm that your patch works, so I've modified mine to only affect record full. See the updated version below. I think it's better if you do the btrace changes yourself, if possible. I also think it would be good to add a test for "record btrace" while the target is running, at least a simple one. I sketched one here, but I don't know if you'd prefer to have it with the other btrace tests or not... Feel free to use it if you want, here it is: https://github.com/simark/binutils-gdb/commit/b4c494125f11499ef6c4d912067348bbeb02b139 Note that the doc seems to confirm that it's not intended to be possible to use "record full" while the target is running: If the inferior is in the non-stop mode (see Non-Stop Mode) or in the asynchronous execution mode (see Background Execution), not all recording methods are available. The full recording method does not support these two modes. Source: https://sourceware.org/gdb/onlinedocs/gdb/Process-Record-and-Replay.html Perhaps it would also be good to mention in the doc that btrace allows you to start it while the program is running, with the caveat you mentioned, that the recording will only start at the next branch. Here is the updated patch: From 20bd7f6b38a69ae3d529427a11c281e2116272e7 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 24 Nov 2016 13:45:10 -0500 Subject: [PATCH] Prevent turning record on while threads are running (PR 20869) As stated in the bug description, trying to do "record" while threads are running leads to a broken state. I tried to see in the code if there was anything to try to support the use case of enabling record while the program is running, but didn't find anything. When full/software recording is active, we are single stepping each instruction. Transitioning from the state where threads are running freely (no recording) to recording enabled should therefore involve a step where we stop them to initiate the single stepping. I can't find anything that looks like this, so my conclusion is that this was never a supported use case (please correct me if I'm wrong). The doc seems to confirm this: If the inferior is in the non-stop mode (see Non-Stop Mode) or in the asynchronous execution mode (see Background Execution), not all recording methods are available. The full recording method does not support these two modes. The easy solution is to prevent the user for enabling record if a thread is running. No regression on the buildbot. gdb/ChangeLog: * record-full.c (record_preopen): Error out if any thread is running. gdb/testsuite: * gdb.reverse/record-while-running.c: New file. * gdb.reverse/record-while-running.exp: New file. --- gdb/record-full.c | 10 ++++ gdb/testsuite/gdb.reverse/record-while-running.c | 29 ++++++++++ gdb/testsuite/gdb.reverse/record-while-running.exp | 67 ++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 gdb/testsuite/gdb.reverse/record-while-running.c create mode 100644 gdb/testsuite/gdb.reverse/record-while-running.exp diff --git a/gdb/record-full.c b/gdb/record-full.c index 5608e70..9c3660f 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -834,6 +834,16 @@ record_full_open_1 (const char *name, int from_tty) error (_("Process record: the current architecture doesn't support " "record function.")); + /* We can't enable record while threads are running, so make sure it's not + the case. */ + iterate_over_threads([] (struct thread_info *tp, void *) -> int { + if (tp->state == thread_state::THREAD_RUNNING) + error (_("Can't enable record while the program is running. Use " + "\"interrupt\" to stop it first.")); + + return 0; + }, NULL); + push_target (&record_full_ops); } diff --git a/gdb/testsuite/gdb.reverse/record-while-running.c b/gdb/testsuite/gdb.reverse/record-while-running.c new file mode 100644 index 0000000..f00ceb6 --- /dev/null +++ b/gdb/testsuite/gdb.reverse/record-while-running.c @@ -0,0 +1,29 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2016 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +int +main () +{ + int i; + + for (i = 0; i < 30; i++) + sleep (1); + + return 0; +} diff --git a/gdb/testsuite/gdb.reverse/record-while-running.exp b/gdb/testsuite/gdb.reverse/record-while-running.exp new file mode 100644 index 0000000..18a85b5 --- /dev/null +++ b/gdb/testsuite/gdb.reverse/record-while-running.exp @@ -0,0 +1,67 @@ +# Copyright 2016 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Test that trying to turn on recording while the target is running is correctly +# handled. + +if ![supports_reverse] { + untested "reverse debugging not supported" + return +} + +standard_testfile + +if { [prepare_for_testing $testfile.exp $testfile $srcfile] } { + fail "failed to compile" + return +} + +if { ![runto_main] } { + fail "couldn't run to main" + return +} + +# Interrupt the target and consume the stop event. + +proc interrupt_target { } { + global gdb_prompt + + # Interrupt the target. + set test "interrupt target" + gdb_test_multiple "interrupt" $test { + -re "interrupt\r\n$gdb_prompt" { + pass $test + } + } + + # Consume the leftovers from the async stop caused by the interrupt. + gdb_test "print 123" ".*Program received signal SIGINT, Interrupt.* = 123" "consume stop event" +} + +# Test that "record full" while the target is running fails gracefully. + +proc_with_prefix test_record_full_while_running { } { + gdb_test "continue &" "Continuing." "resume target" + gdb_test \ + "record full" \ + "Can't enable record while the program is running. Use \"interrupt\" to stop it first." \ + "switch record on while target is running" + + # Interrupt the target to make sure the test ends gracefully when testing + # remotely. + interrupt_target +} + +test_record_full_while_running