From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 103802 invoked by alias); 22 Apr 2019 13:15:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 103669 invoked by uid 89); 22 Apr 2019 13:15:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.1 spammy=out, trial, waitpid, sk:status_ X-HELO: mailsec116.isp.belgacom.be Received: from mailsec116.isp.belgacom.be (HELO mailsec116.isp.belgacom.be) (195.238.20.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 22 Apr 2019 13:15:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1555938947; x=1587474947; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=nGwjYDlxSYE3+4UA1JHL6gNZFyF5GLevOfuOlhPt5nQ=; b=YaUfmoqFLJdVNaMHgvWwfjxh6e4Tujxj/PNmfnENhF/G0LgAhgsNH2WN 5PXJRrGOSAb3dZFGZ9gMn4vMguaUNg==; Received: from 45.123-131-109.adsl-dyn.isp.belgacom.be (HELO md) ([109.131.123.45]) by relay.skynet.be with ESMTP/TLS/AES256-GCM-SHA384; 22 Apr 2019 15:15:44 +0200 Message-ID: <1555938944.22002.1.camel@skynet.be> Subject: Re: [RFA 2/4] Implement | (pipe) command. From: Philippe Waroquiers To: Eli Zaretskii Cc: gdb-patches@sourceware.org Date: Mon, 22 Apr 2019 13:15:00 -0000 In-Reply-To: <83tveq70w8.fsf@gnu.org> References: <20190420212153.30934-1-philippe.waroquiers@skynet.be> <20190420212153.30934-3-philippe.waroquiers@skynet.be> <83r29w9bpw.fsf@gnu.org> <1555839622.6208.17.camel@skynet.be> <838sw3acgz.fsf@gnu.org> <1555929000.6208.20.camel@skynet.be> <83tveq70w8.fsf@gnu.org> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2019-04/txt/msg00416.txt.bz2 On Mon, 2019-04-22 at 14:08 +0300, Eli Zaretskii wrote: > > From: Philippe Waroquiers > > Cc: gdb-patches@sourceware.org > > Date: Mon, 22 Apr 2019 12:30:00 +0200 > > > > Currently, on MingW, the above macros (WIFEXITED, WIFSIGNALED, ...) > > are not defined. > > I think gdb_wait.h does define them for MinGW, it's just that those > definitions are currently unused anywhere that is compiled into the > MinGW build. > > > So, the idea is to have gdb_wait.h defining them on MingW, > > with something like: > > > > #ifndef WIFEXITED > > #if defined (__MINGW32__) > > #define WIFEXITED(stat_val)   (((stat_val) & 0xC0000000) == 0) > > #else > > #define WIFEXITED(w) (((w)&0377) == 0) > > #endif > > #endif > > > > Then in windows-nat.c, implement windows_status_to_termsig > > that searches in xlate for stat_val & ~0xC0000000 to give > > the equivalent signal. > > > > Does the above look reasonable ? > > Yes, thanks. So, here is a trial patch, only compiled on Debian/amd64. Does that compile/work on MingW ? Thanks Philippe diff --git a/gdb/common/gdb_wait.h b/gdb/common/gdb_wait.h index b3b752cf3a..ca95240009 100644 --- a/gdb/common/gdb_wait.h +++ b/gdb/common/gdb_wait.h @@ -40,13 +40,31 @@     NOTE exception for GNU/Linux below).  We also fail to declare     wait() and waitpid().  */   +/* For MINGW, the underlying idea is that when a Windows program is terminated +   by a fatal exception, its exit code is the value of that exception, as +   defined by the various STATUS_* symbols in the Windows API headers. + +   The below is not perfect, because a program could legitimately exit normally +   with a status whose value happens to have the high bits set, but that's +   extremely rare, to say the least, and it is deemed such a negligibly small +   probability of false positives is justified by the utility of reporting the +   terminating signal in the "normal" cases.  */ +  #ifndef WIFEXITED +#if defined (__MINGW32__) +#define WIFEXITED(stat_val)   (((stat_val) & 0xC0000000) == 0) +#else  #define WIFEXITED(w) (((w)&0377) == 0)  #endif +#endif    #ifndef WIFSIGNALED +#if defined (__MINGW32__) +#define WIFSIGNALED(stat_val) (((stat_val) & 0xC0000000) == 0xC0000000) +#else  #define WIFSIGNALED(w) (((w)&0377) != 0177 && ((w)&~0377) == 0)  #endif +#endif    #ifndef WIFSTOPPED  #ifdef IBM6000 @@ -64,12 +82,21 @@  #endif    #ifndef WEXITSTATUS +#if defined (__MINGW32__) +#define WEXITSTATUS(stat_val) ((stat_val) & 255) +#else  #define WEXITSTATUS(w) (((w) >> 8) & 0377) /* same as WRETCODE */  #endif +#endif    #ifndef WTERMSIG +#if defined (__MINGW32__) +extern enum gdb_signal windows_status_to_termsig (int stat_val); +#define WTERMSIG(stat_val)    windows_status_to_termsig (stat_val) +#else  #define WTERMSIG(w) ((w) & 0177)  #endif +#endif    #ifndef WSTOPSIG  #define WSTOPSIG WEXITSTATUS diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 50094187bd..e12cf10416 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -281,9 +281,9 @@ static const int *mappings;     a segment register or not.  */  static segment_register_p_ftype *segment_register_p;   -/* See windows_nat_target::resume to understand why this is commented -   out.  */ -#if 0 +/* See windows_nat_target::resume to understand why xlate is not used +   to translate a signal into an exception.  */ +  /* This vector maps the target's idea of an exception (extracted     from the DEBUG_EVENT structure) to GDB's idea.  */   @@ -303,7 +303,17 @@ static const struct xlate_exception xlate[] =    {STATUS_FLOAT_DIVIDE_BY_ZERO, GDB_SIGNAL_FPE}  };   -#endif /* 0 */ +/* Translate a windows exception inside STAT_VAL into a gdb_signal. +   This should only be called if WIFSIGNALED(stat_val).  */ + +enum gdb_signal +windows_status_to_termsig (int stat_val) +{ +  for (const xlate_exception &x : xlate) +    if (x.them == (stat_val & ~0xC0000000)) +      return x.us; +  return GDB_SIGNAL_UNKNOWN; +}    struct windows_nat_target final : public x86_nat_target  {