public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* GDB is preventing my catch blocks in my C++ program
@ 2022-04-13  0:27 Claude Robitaille
  2022-04-13  1:17 ` Simon Marchi
  0 siblings, 1 reply; 7+ messages in thread
From: Claude Robitaille @ 2022-04-13  0:27 UTC (permalink / raw)
  To: gdb

Hi all,

I am having an issue with exception in C++. When I run my program outside gdb (gsbserver actually) all is good and my exceptions are properly catched.

However, when running un gdbserver I get:
"terminate called after throwing an instance of XXXX"

The actuall catch statmeent is catch (...) so it is a catch all.

I obvisouly suspect that, somehow, gdbserver is preventing the normal try/catch/throw machinery to work as it should. The "terminate called..." string is most likely coming form the language library.

Background
I am crosscompiling with mingw-w64 on Ubuntu. The compiler is 9.3 while both gdb and gdbserver are 9.1 I run gdb under eclipse

I run under WIndows 10

I spend the whole afternoon on Google but all I found are cases where the programmer did not properly coded the catch (or something similar), which, indeed, is not my problem since all is good when running outside of gdb.

Not sure how to tackle this one!!



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: GDB is preventing my catch blocks in my C++ program
  2022-04-13  0:27 GDB is preventing my catch blocks in my C++ program Claude Robitaille
@ 2022-04-13  1:17 ` Simon Marchi
       [not found]   ` <DS7PR07MB768661F868A4131D995B3449F7EC9@DS7PR07MB7686.namprd07.prod.outlook.com>
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Marchi @ 2022-04-13  1:17 UTC (permalink / raw)
  To: Claude Robitaille, gdb



On 2022-04-12 20:27, Claude Robitaille via Gdb wrote:
> Hi all,
> 
> I am having an issue with exception in C++. When I run my program outside gdb (gsbserver actually) all is good and my exceptions are properly catched.
> 
> However, when running un gdbserver I get:
> "terminate called after throwing an instance of XXXX"
> 
> The actuall catch statmeent is catch (...) so it is a catch all.
> 
> I obvisouly suspect that, somehow, gdbserver is preventing the normal try/catch/throw machinery to work as it should. The "terminate called..." string is most likely coming form the language library.
> 
> Background
> I am crosscompiling with mingw-w64 on Ubuntu. The compiler is 9.3 while both gdb and gdbserver are 9.1 I run gdb under eclipse
> 
> I run under WIndows 10
> 
> I spend the whole afternoon on Google but all I found are cases where the programmer did not properly coded the catch (or something similar), which, indeed, is not my problem since all is good when running outside of gdb.
> 
> Not sure how to tackle this one!!

Just to try to get the obvious out of the way first... are you sure it's
not GDBserver itself crashing?  GDBserver is a C++ program, so it's
possible that an exception is thrown and not caught in it.

Can you paste the logs of a session that shows your problem?

GDBserver and your program are running on Windows IIUC?

Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: GDB is preventing my catch blocks in my C++ program
       [not found]   ` <DS7PR07MB768661F868A4131D995B3449F7EC9@DS7PR07MB7686.namprd07.prod.outlook.com>
@ 2022-04-13  1:33     ` Simon Marchi
  2022-04-13  1:39     ` Claude Robitaille
  1 sibling, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2022-04-13  1:33 UTC (permalink / raw)
  To: Claude Robitaille, gdb

Hi Claude,

Please make sure to do a reply all so everyone on the list can see your
reply and contribute.

On 2022-04-12 21:28, Claude Robitaille wrote:
> Thanks Simon for the quick reply.
> 
> I can single step the program up to the point where an exception is thrown. And I did set a breakpoint inside the catch statement but no success (earlier breakpoint in the code are working as expected).
> 
> Here is what appears on the console (yes, it is Windows)
> 
> Listening on port 2345
> Remote debugging from host 192.168.70.8, port 34542
> Error while doing a GetTokenInformation - Unknown errorLOGGER NOT INITIALIZED:
>                 *********************************************************************************************
> terminate called after throwing an instance of 'sf::context::tGlobal::envVariableMissing'
> 
> Child exited with status 3

> 
> 
> The string that starts with Error blah blah is my own std::cout earlier in the program. Same with the line with the ******
> and the LOGGER xxxx is from the g3log library in my program.
> 
> The exception instance is definitely what my program is throwing.

Indeed, that makes it clear it's not gdbserver crashing.

I don't have any idea at the moment about how gdb/gdbserver could affect
the execution of your program in this way.

> I guess Child exited is from gdb.

Yes.

Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: GDB is preventing my catch blocks in my C++ program
       [not found]   ` <DS7PR07MB768661F868A4131D995B3449F7EC9@DS7PR07MB7686.namprd07.prod.outlook.com>
  2022-04-13  1:33     ` Simon Marchi
@ 2022-04-13  1:39     ` Claude Robitaille
  2022-04-14 15:06       ` Claude Robitaille
  1 sibling, 1 reply; 7+ messages in thread
From: Claude Robitaille @ 2022-04-13  1:39 UTC (permalink / raw)
  To: Simon Marchi, gdb

To include the list...
________________________________
From: Claude Robitaille <claude-robitaille@hotmail.com>
Sent: April 12, 2022 9:28 PM
To: Simon Marchi <simon.marchi@polymtl.ca>
Subject: Re: GDB is preventing my catch blocks in my C++ program

Thanks Simon for the quick reply.

I can single step the program up to the point where an exception is thrown. And I did set a breakpoint inside the catch statement but no success (earlier breakpoint in the code are working as expected).

Here is what appears on the console (yes, it is Windows)

Listening on port 2345
Remote debugging from host 192.168.70.8, port 34542
Error while doing a GetTokenInformation - Unknown errorLOGGER NOT INITIALIZED:
                *********************************************************************************************
terminate called after throwing an instance of 'sf::context::tGlobal::envVariableMissing'

Child exited with status 3


The string that starts with Error blah blah is my own std::cout earlier in the program. Same with the line with the ******
and the LOGGER xxxx is from the g3log library in my program.

The exception instance is definitely what my program is throwing.

I guess Child exited is from gdb.


________________________________
From: Simon Marchi <simon.marchi@polymtl.ca>
Sent: April 12, 2022 9:17 PM
To: Claude Robitaille <claude-robitaille@hotmail.com>; gdb@sourceware.org <gdb@sourceware.org>
Subject: Re: GDB is preventing my catch blocks in my C++ program



On 2022-04-12 20:27, Claude Robitaille via Gdb wrote:
> Hi all,
>
> I am having an issue with exception in C++. When I run my program outside gdb (gsbserver actually) all is good and my exceptions are properly catched.
>
> However, when running un gdbserver I get:
> "terminate called after throwing an instance of XXXX"
>
> The actuall catch statmeent is catch (...) so it is a catch all.
>
> I obvisouly suspect that, somehow, gdbserver is preventing the normal try/catch/throw machinery to work as it should. The "terminate called..." string is most likely coming form the language library.
>
> Background
> I am crosscompiling with mingw-w64 on Ubuntu. The compiler is 9.3 while both gdb and gdbserver are 9.1 I run gdb under eclipse
>
> I run under WIndows 10
>
> I spend the whole afternoon on Google but all I found are cases where the programmer did not properly coded the catch (or something similar), which, indeed, is not my problem since all is good when running outside of gdb.
>
> Not sure how to tackle this one!!

Just to try to get the obvious out of the way first... are you sure it's
not GDBserver itself crashing?  GDBserver is a C++ program, so it's
possible that an exception is thrown and not caught in it.

Can you paste the logs of a session that shows your problem?

GDBserver and your program are running on Windows IIUC?

Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: GDB is preventing my catch blocks in my C++ program
  2022-04-13  1:39     ` Claude Robitaille
@ 2022-04-14 15:06       ` Claude Robitaille
  2022-04-15 15:55         ` Claude Robitaille
  0 siblings, 1 reply; 7+ messages in thread
From: Claude Robitaille @ 2022-04-14 15:06 UTC (permalink / raw)
  To: Simon Marchi, gdb, Claude Robitaille

I created a sample program to reproduce the issues.

#include<iostream>
#include <stdexcept>
int main()
{
  std::cout<<"Before the try block" << std::endl;

  try {
    throw std::runtime_error("Test exception");
  } catch (...) {
    std::cout << "Catched the exception" << std::endl;
  }

  std::cout<<"After the try block" << std::endl;
  return 0;
}


I compiled it using this

x86_64-w64-mingw32-g++ -static hello.cpp -static-libstdc++ -static-libgcc -o hello

When running outside gdb, I get this output

Before the try block
Catched the exception
After the try block


But under gdbserver, I get

Listening on port 2345
Remote debugging from host 192.168.70.8, port 44782
Before the try block
terminate called after throwing an instance of 'std::runtime_error'

Child exited with status 3






________________________________
From: Gdb <gdb-bounces+claude=cbcr.me@sourceware.org> on behalf of Claude Robitaille via Gdb <gdb@sourceware.org>
Sent: April 12, 2022 9:39 PM
To: Simon Marchi <simon.marchi@polymtl.ca>; gdb@sourceware.org <gdb@sourceware.org>
Subject: Re: GDB is preventing my catch blocks in my C++ program

To include the list...
________________________________
From: Claude Robitaille <claude-robitaille@hotmail.com>
Sent: April 12, 2022 9:28 PM
To: Simon Marchi <simon.marchi@polymtl.ca>
Subject: Re: GDB is preventing my catch blocks in my C++ program

Thanks Simon for the quick reply.

I can single step the program up to the point where an exception is thrown. And I did set a breakpoint inside the catch statement but no success (earlier breakpoint in the code are working as expected).

Here is what appears on the console (yes, it is Windows)

Listening on port 2345
Remote debugging from host 192.168.70.8, port 34542
Error while doing a GetTokenInformation - Unknown errorLOGGER NOT INITIALIZED:
                *********************************************************************************************
terminate called after throwing an instance of 'sf::context::tGlobal::envVariableMissing'

Child exited with status 3


The string that starts with Error blah blah is my own std::cout earlier in the program. Same with the line with the ******
and the LOGGER xxxx is from the g3log library in my program.

The exception instance is definitely what my program is throwing.

I guess Child exited is from gdb.


________________________________
From: Simon Marchi <simon.marchi@polymtl.ca>
Sent: April 12, 2022 9:17 PM
To: Claude Robitaille <claude-robitaille@hotmail.com>; gdb@sourceware.org <gdb@sourceware.org>
Subject: Re: GDB is preventing my catch blocks in my C++ program



On 2022-04-12 20:27, Claude Robitaille via Gdb wrote:
> Hi all,
>
> I am having an issue with exception in C++. When I run my program outside gdb (gsbserver actually) all is good and my exceptions are properly catched.
>
> However, when running un gdbserver I get:
> "terminate called after throwing an instance of XXXX"
>
> The actuall catch statmeent is catch (...) so it is a catch all.
>
> I obvisouly suspect that, somehow, gdbserver is preventing the normal try/catch/throw machinery to work as it should. The "terminate called..." string is most likely coming form the language library.
>
> Background
> I am crosscompiling with mingw-w64 on Ubuntu. The compiler is 9.3 while both gdb and gdbserver are 9.1 I run gdb under eclipse
>
> I run under WIndows 10
>
> I spend the whole afternoon on Google but all I found are cases where the programmer did not properly coded the catch (or something similar), which, indeed, is not my problem since all is good when running outside of gdb.
>
> Not sure how to tackle this one!!

Just to try to get the obvious out of the way first... are you sure it's
not GDBserver itself crashing?  GDBserver is a C++ program, so it's
possible that an exception is thrown and not caught in it.

Can you paste the logs of a session that shows your problem?

GDBserver and your program are running on Windows IIUC?

Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: GDB is preventing my catch blocks in my C++ program
  2022-04-14 15:06       ` Claude Robitaille
@ 2022-04-15 15:55         ` Claude Robitaille
  2022-04-18  0:45           ` Simon Marchi
  0 siblings, 1 reply; 7+ messages in thread
From: Claude Robitaille @ 2022-04-15 15:55 UTC (permalink / raw)
  To: Simon Marchi, gdb

Simon,

Someone is pointing to a bug, that you fix, that explains the behaviour I am seeing. Do you concur? Here is the commit

https://sourceware.org/git/?p=binutils-gdb.git;a=commit;f=gdb/nat/windows-nat.c;h=183be222907a6f419bd71f70ee650989026f0188

Claude
________________________________
From: Claude Robitaille <claude-robitaille@hotmail.com>
Sent: April 14, 2022 11:06 AM
To: Simon Marchi <simon.marchi@polymtl.ca>; gdb@sourceware.org <gdb@sourceware.org>; Claude Robitaille <claude-robitaille@hotmail.com>
Subject: Re: GDB is preventing my catch blocks in my C++ program


I created a sample program to reproduce the issues.

#include<iostream>
#include <stdexcept>
int main()
{
  std::cout<<"Before the try block" << std::endl;

  try {
    throw std::runtime_error("Test exception");
  } catch (...) {
    std::cout << "Catched the exception" << std::endl;
  }

  std::cout<<"After the try block" << std::endl;
  return 0;
}


I compiled it using this

x86_64-w64-mingw32-g++ -static hello.cpp -static-libstdc++ -static-libgcc -o hello

When running outside gdb, I get this output

Before the try block
Catched the exception
After the try block


But under gdbserver, I get

Listening on port 2345
Remote debugging from host 192.168.70.8, port 44782
Before the try block
terminate called after throwing an instance of 'std::runtime_error'

Child exited with status 3






________________________________
From: Gdb <gdb-bounces+claude=cbcr.me@sourceware.org> on behalf of Claude Robitaille via Gdb <gdb@sourceware.org>
Sent: April 12, 2022 9:39 PM
To: Simon Marchi <simon.marchi@polymtl.ca>; gdb@sourceware.org <gdb@sourceware.org>
Subject: Re: GDB is preventing my catch blocks in my C++ program

To include the list...
________________________________
From: Claude Robitaille <claude-robitaille@hotmail.com>
Sent: April 12, 2022 9:28 PM
To: Simon Marchi <simon.marchi@polymtl.ca>
Subject: Re: GDB is preventing my catch blocks in my C++ program

Thanks Simon for the quick reply.

I can single step the program up to the point where an exception is thrown. And I did set a breakpoint inside the catch statement but no success (earlier breakpoint in the code are working as expected).

Here is what appears on the console (yes, it is Windows)

Listening on port 2345
Remote debugging from host 192.168.70.8, port 34542
Error while doing a GetTokenInformation - Unknown errorLOGGER NOT INITIALIZED:
                *********************************************************************************************
terminate called after throwing an instance of 'sf::context::tGlobal::envVariableMissing'

Child exited with status 3


The string that starts with Error blah blah is my own std::cout earlier in the program. Same with the line with the ******
and the LOGGER xxxx is from the g3log library in my program.

The exception instance is definitely what my program is throwing.

I guess Child exited is from gdb.


________________________________
From: Simon Marchi <simon.marchi@polymtl.ca>
Sent: April 12, 2022 9:17 PM
To: Claude Robitaille <claude-robitaille@hotmail.com>; gdb@sourceware.org <gdb@sourceware.org>
Subject: Re: GDB is preventing my catch blocks in my C++ program



On 2022-04-12 20:27, Claude Robitaille via Gdb wrote:
> Hi all,
>
> I am having an issue with exception in C++. When I run my program outside gdb (gsbserver actually) all is good and my exceptions are properly catched.
>
> However, when running un gdbserver I get:
> "terminate called after throwing an instance of XXXX"
>
> The actuall catch statmeent is catch (...) so it is a catch all.
>
> I obvisouly suspect that, somehow, gdbserver is preventing the normal try/catch/throw machinery to work as it should. The "terminate called..." string is most likely coming form the language library.
>
> Background
> I am crosscompiling with mingw-w64 on Ubuntu. The compiler is 9.3 while both gdb and gdbserver are 9.1 I run gdb under eclipse
>
> I run under WIndows 10
>
> I spend the whole afternoon on Google but all I found are cases where the programmer did not properly coded the catch (or something similar), which, indeed, is not my problem since all is good when running outside of gdb.
>
> Not sure how to tackle this one!!

Just to try to get the obvious out of the way first... are you sure it's
not GDBserver itself crashing?  GDBserver is a C++ program, so it's
possible that an exception is thrown and not caught in it.

Can you paste the logs of a session that shows your problem?

GDBserver and your program are running on Windows IIUC?

Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: GDB is preventing my catch blocks in my C++ program
  2022-04-15 15:55         ` Claude Robitaille
@ 2022-04-18  0:45           ` Simon Marchi
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2022-04-18  0:45 UTC (permalink / raw)
  To: Claude Robitaille, gdb



On 2022-04-15 11:55, Claude Robitaille wrote:
> Simon,
> 
> Someone is pointing to a bug, that you fix, that explains the behaviour I am seeing. Do you concur? Here is the commit
> 
> https://sourceware.org/git/?p=binutils-gdb.git;a=commit;f=gdb/nat/windows-nat.c;h=183be222907a6f419bd71f70ee650989026f0188 <https://sourceware.org/git/?p=binutils-gdb.git;a=commit;f=gdb/nat/windows-nat.c;h=183be222907a6f419bd71f70ee650989026f0188>
> 
> Claude

I don't really see how that commit relates to the problem you
are seeing.

Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-04-18  0:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-13  0:27 GDB is preventing my catch blocks in my C++ program Claude Robitaille
2022-04-13  1:17 ` Simon Marchi
     [not found]   ` <DS7PR07MB768661F868A4131D995B3449F7EC9@DS7PR07MB7686.namprd07.prod.outlook.com>
2022-04-13  1:33     ` Simon Marchi
2022-04-13  1:39     ` Claude Robitaille
2022-04-14 15:06       ` Claude Robitaille
2022-04-15 15:55         ` Claude Robitaille
2022-04-18  0:45           ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).