krytarowski added inline comments.

================
Comment at: include/lldb/Core/Debugger.h:379
   lldb::ListenerSP m_forward_listener_sp;
-  std::once_flag m_clear_once;
+  llvm::once_flag m_clear_once;
 
----------------
labath wrote:
> The code in llvm says you should only ever use the LLVM_DEFINE_ONCE_FLAG to 
> declare flags. I am guessing it's because it forces the `static` keyword into 
> the declaration, which in turn guarantees your object will be 
> zero-initialized by the linker. If you declare the flag as a local variable 
> like this, it will be initialized to a random value, and you will have a fun 
> time debugging issues in the future (it will only affect netbsd, as 
> std::call_once platforms will still be correctly initialized).
I was thinking about it, there is `m_clear_once()` in  
`lldb/source/Core/Debugger.cpp` used in the initializer. But apparently there 
is no zeroing it with this.

Similar case is in DWARFDataSegment.

```
struct DWARFDataSegment {
    llvm::once_flag m_flag;
    lldb_private::DWARFDataExtractor m_data;
  };
```

And another one with `static llvm::ManagedStatic<llvm::once_flag> g_once_flag;` 
(I don't fully understand the impact here).

Is there an option to turn `llvm::once_flag` to behave like `std::once_flag`? 
For example changing once_flag to a class like:

```
class once_flag
{
once_flag() : status(Uninitialized) {};
llvm::sys::cas_flag status;
};
```

and replace occurrences of `flag` with `flag.status`.

Perhaps it would change the code to mechanical replacement of `std::once_flag` 
and `std::call_ones` to `llvm::` versions.


Repository:
  rL LLVM

https://reviews.llvm.org/D29288



_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to