C++ Logo

sg15

Advanced search

Re: [SG15] breakpoint and is_debugger_present proposals.

From: Ben Boeckel <ben.boeckel_at_[hidden]>
Date: Sun, 16 Jan 2022 07:53:22 -0500
On Sat, Jan 15, 2022 at 20:32:32 -0600, René Ferdinand Rivera Morell wrote:
> On Wed, Jan 5, 2022 at 6:10 AM Ben Boeckel <ben.boeckel_at_[hidden]> wrote:
>
> > On Wed, Jan 05, 2022 at 08:10:08 +0000, Jonathan Wakely via SG15 wrote:
> > > Maybe give it a default argument too. The difficulty then is whether it
> > > should default to true or false, and whether true should mean conditional
> > > or unconditional.
> >
> > Why are we limited to `bool`? Why not something like:
> >
> > ```
> > enum class breakport_condition {
> > always,
> > when_debugged, // best effort
> > never, // to allow for more complicated conditional logic leading up
> > to the call
> > };
> > ```
> >
> > The discussion of the default is then down to just `always` or
> > `when_debugged`, no?
> >
>
> I don't see what "never" does? There's only one check to skip or not, so I
> would think there's only two alternatives to choose from.

It allows something like:

```
const char* env = getenv("ENABLE_BREAKPOINTS");
std::string dbg = env ? env : "";
std::breakport_condition cond = std::breakport_condition::never;
if (dbg == "yes")
  cond = std::breakport_condition::always;
else if (dbg == "try")
  cond = std::breakport_condition::when_debugged;
std::breakpoint(cond);
```

instead of:

```
const char* env = getenv("ENABLE_BREAKPOINTS");
std::string dbg = env ? env : "";
bool use_cond = false;
bool cond = false;
if (dbg == "yes") {
  use_cond = true;
  cond = true;
} else if (dbg == "try") {
  use_cond = true;
  cond = false;
}
if (use_cond)
  std::breakpoint(cond);
```

I think the former is *far* better than boolean soup.

--Ben

Received on 2022-01-16 12:53:24