[Lldb-commits] [PATCH] D32271: Patch to Attach pid successfully from different dir

2017-05-19 Thread Dimitry Andric via Phabricator via lldb-commits
dim added a comment.

As I found out in https://reviews.llvm.org/rL303015, the `KERN_PROC_PATHNAME` 
has one drawback: if an executable file has multiple hard links, you will get 
just one of its filenames as the result.  Since that filename is more or less 
randomly chosen, it does *not* have to correspond to the actual `argv[0]` the 
executable was invoked with.  If that does not matter, this approach is fine, 
though.


https://reviews.llvm.org/D32271



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


[Lldb-commits] [PATCH] D115074: [lldb/lua] Suppress warnings about C-linkage in generated wrapper

2021-12-03 Thread Dimitry Andric via Phabricator via lldb-commits
dim created this revision.
dim added reviewers: tammela, siger-young, emaste.
dim requested review of this revision.
Herald added a project: LLDB.

When lldb Lua bindings are enabled, the generated `LLDBWrapLua.cpp` file
generates a compiler warning about C-linkage:

  lldb/LLDBWrapLua.cpp:71170:1: warning: 
'LLDBSwigLuaBreakpointCallbackFunction' has C-linkage specified, but returns 
incomplete type 'llvm::Expected' which could be incompatible with C

In `lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp` these warnings
are suppressed using a few pragmas. Also Add these to `lua-wrapper.swig`
so they end up in `LLDBWrapLua.cpp`, making the warnings disappear.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115074

Files:
  lldb/bindings/lua/lua-wrapper.swig


Index: lldb/bindings/lua/lua-wrapper.swig
===
--- lldb/bindings/lua/lua-wrapper.swig
+++ lldb/bindings/lua/lua-wrapper.swig
@@ -21,6 +21,17 @@
 
 %wrapper %{
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
+
+// Disable warning C4190: 'LLDBSwigPythonBreakpointCallbackFunction' has
+// C-linkage specified, but returns UDT 'llvm::Expected' which is
+// incompatible with C
+#if _MSC_VER
+#pragma warning (push)
+#pragma warning (disable : 4190)
+#endif
+
 // This function is called from Lua::CallBreakpointCallback
 SWIGEXPORT llvm::Expected
 LLDBSwigLuaBreakpointCallbackFunction
@@ -101,6 +112,12 @@
return stop;
 }
 
+#if _MSC_VER
+#pragma warning (pop)
+#endif
+
+#pragma clang diagnostic pop
+
 SWIGEXPORT void
 LLDBSwigLuaCallLuaLogOutputCallback(const char *str, void *baton) {
lua_State *L = (lua_State *)baton;


Index: lldb/bindings/lua/lua-wrapper.swig
===
--- lldb/bindings/lua/lua-wrapper.swig
+++ lldb/bindings/lua/lua-wrapper.swig
@@ -21,6 +21,17 @@
 
 %wrapper %{
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
+
+// Disable warning C4190: 'LLDBSwigPythonBreakpointCallbackFunction' has
+// C-linkage specified, but returns UDT 'llvm::Expected' which is
+// incompatible with C
+#if _MSC_VER
+#pragma warning (push)
+#pragma warning (disable : 4190)
+#endif
+
 // This function is called from Lua::CallBreakpointCallback
 SWIGEXPORT llvm::Expected
 LLDBSwigLuaBreakpointCallbackFunction
@@ -101,6 +112,12 @@
return stop;
 }
 
+#if _MSC_VER
+#pragma warning (pop)
+#endif
+
+#pragma clang diagnostic pop
+
 SWIGEXPORT void
 LLDBSwigLuaCallLuaLogOutputCallback(const char *str, void *baton) {
lua_State *L = (lua_State *)baton;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D115074: [lldb/lua] Suppress warnings about C-linkage in generated wrapper

2021-12-04 Thread Dimitry Andric via Phabricator via lldb-commits
dim added a comment.

In D115074#3170635 , @JDevlieghere 
wrote:

> We should move this from the wrapper to the header block, similar to what 
> Pavel did for Python: 
> https://reviews.llvm.org/rG9a14adeae00015798843ff5cad987e5fdbdddb34

I agree, but I'm not really qualified to do this. I just wanted to get rid of 
the warning. :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115074/new/

https://reviews.llvm.org/D115074

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


[Lldb-commits] [PATCH] D124672: [lldb] Define LLDB_VERSION_PATCH correctly

2022-04-29 Thread Dimitry Andric via Phabricator via lldb-commits
dim created this revision.
dim added reviewers: JDevlieghere, labath.
Herald added a project: All.
dim requested review of this revision.
Herald added a project: LLDB.

In commit ccf1469a4cdb 
 lldb got 
its own generated Version.inc file, with
`LLDB_VERSION` macros. However, it used `LLDB_VERSION_PATCHLEVEL`
instead of the actually correct `LLDB_VERSION_PATCH`. Correct this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124672

Files:
  lldb/include/lldb/Version/Version.inc.in


Index: lldb/include/lldb/Version/Version.inc.in
===
--- lldb/include/lldb/Version/Version.inc.in
+++ lldb/include/lldb/Version/Version.inc.in
@@ -2,5 +2,5 @@
 #define LLDB_VERSION_STRING "@LLDB_VERSION@"
 #define LLDB_VERSION_MAJOR @LLDB_VERSION_MAJOR@
 #define LLDB_VERSION_MINOR @LLDB_VERSION_MINOR@
-#define LLDB_VERSION_PATCHLEVEL @LLDB_VERSION_PATCHLEVEL@
+#define LLDB_VERSION_PATCH @LLDB_VERSION_PATCH@
 #cmakedefine LLDB_FULL_VERSION_STRING "@LLDB_FULL_VERSION_STRING@"


Index: lldb/include/lldb/Version/Version.inc.in
===
--- lldb/include/lldb/Version/Version.inc.in
+++ lldb/include/lldb/Version/Version.inc.in
@@ -2,5 +2,5 @@
 #define LLDB_VERSION_STRING "@LLDB_VERSION@"
 #define LLDB_VERSION_MAJOR @LLDB_VERSION_MAJOR@
 #define LLDB_VERSION_MINOR @LLDB_VERSION_MINOR@
-#define LLDB_VERSION_PATCHLEVEL @LLDB_VERSION_PATCHLEVEL@
+#define LLDB_VERSION_PATCH @LLDB_VERSION_PATCH@
 #cmakedefine LLDB_FULL_VERSION_STRING "@LLDB_FULL_VERSION_STRING@"
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D124672: [lldb] Define LLDB_VERSION_PATCH correctly

2022-04-29 Thread Dimitry Andric via Phabricator via lldb-commits
dim updated this revision to Diff 426110.
dim added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Add llvm/utils/gn/secondary/lldb/include/lldb/Version/BUILD.gn while we're here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124672/new/

https://reviews.llvm.org/D124672

Files:
  lldb/include/lldb/Version/Version.inc.in
  llvm/utils/gn/secondary/lldb/include/lldb/Version/BUILD.gn


Index: llvm/utils/gn/secondary/lldb/include/lldb/Version/BUILD.gn
===
--- llvm/utils/gn/secondary/lldb/include/lldb/Version/BUILD.gn
+++ llvm/utils/gn/secondary/lldb/include/lldb/Version/BUILD.gn
@@ -9,7 +9,7 @@
 "LLDB_VERSION=$llvm_version",
 "LLDB_VERSION_MAJOR=$llvm_version_major",
 "LLDB_VERSION_MINOR=$llvm_version_minor",
-"LLDB_VERSION_PATCHLEVEL=$llvm_version_patch",
+"LLDB_VERSION_PATCH=$llvm_version_patch",
 "LLDB_FULL_VERSION_STRING=",
   ]
 }
Index: lldb/include/lldb/Version/Version.inc.in
===
--- lldb/include/lldb/Version/Version.inc.in
+++ lldb/include/lldb/Version/Version.inc.in
@@ -2,5 +2,5 @@
 #define LLDB_VERSION_STRING "@LLDB_VERSION@"
 #define LLDB_VERSION_MAJOR @LLDB_VERSION_MAJOR@
 #define LLDB_VERSION_MINOR @LLDB_VERSION_MINOR@
-#define LLDB_VERSION_PATCHLEVEL @LLDB_VERSION_PATCHLEVEL@
+#define LLDB_VERSION_PATCH @LLDB_VERSION_PATCH@
 #cmakedefine LLDB_FULL_VERSION_STRING "@LLDB_FULL_VERSION_STRING@"


Index: llvm/utils/gn/secondary/lldb/include/lldb/Version/BUILD.gn
===
--- llvm/utils/gn/secondary/lldb/include/lldb/Version/BUILD.gn
+++ llvm/utils/gn/secondary/lldb/include/lldb/Version/BUILD.gn
@@ -9,7 +9,7 @@
 "LLDB_VERSION=$llvm_version",
 "LLDB_VERSION_MAJOR=$llvm_version_major",
 "LLDB_VERSION_MINOR=$llvm_version_minor",
-"LLDB_VERSION_PATCHLEVEL=$llvm_version_patch",
+"LLDB_VERSION_PATCH=$llvm_version_patch",
 "LLDB_FULL_VERSION_STRING=",
   ]
 }
Index: lldb/include/lldb/Version/Version.inc.in
===
--- lldb/include/lldb/Version/Version.inc.in
+++ lldb/include/lldb/Version/Version.inc.in
@@ -2,5 +2,5 @@
 #define LLDB_VERSION_STRING "@LLDB_VERSION@"
 #define LLDB_VERSION_MAJOR @LLDB_VERSION_MAJOR@
 #define LLDB_VERSION_MINOR @LLDB_VERSION_MINOR@
-#define LLDB_VERSION_PATCHLEVEL @LLDB_VERSION_PATCHLEVEL@
+#define LLDB_VERSION_PATCH @LLDB_VERSION_PATCH@
 #cmakedefine LLDB_FULL_VERSION_STRING "@LLDB_FULL_VERSION_STRING@"
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D124672: [lldb] Define LLDB_VERSION_PATCH correctly

2022-04-29 Thread Dimitry Andric via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7abfaa0a815a: [lldb] Define LLDB_VERSION_PATCH correctly 
(authored by dim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124672/new/

https://reviews.llvm.org/D124672

Files:
  lldb/include/lldb/Version/Version.inc.in
  llvm/utils/gn/secondary/lldb/include/lldb/Version/BUILD.gn


Index: llvm/utils/gn/secondary/lldb/include/lldb/Version/BUILD.gn
===
--- llvm/utils/gn/secondary/lldb/include/lldb/Version/BUILD.gn
+++ llvm/utils/gn/secondary/lldb/include/lldb/Version/BUILD.gn
@@ -9,7 +9,7 @@
 "LLDB_VERSION=$llvm_version",
 "LLDB_VERSION_MAJOR=$llvm_version_major",
 "LLDB_VERSION_MINOR=$llvm_version_minor",
-"LLDB_VERSION_PATCHLEVEL=$llvm_version_patch",
+"LLDB_VERSION_PATCH=$llvm_version_patch",
 "LLDB_FULL_VERSION_STRING=",
   ]
 }
Index: lldb/include/lldb/Version/Version.inc.in
===
--- lldb/include/lldb/Version/Version.inc.in
+++ lldb/include/lldb/Version/Version.inc.in
@@ -2,5 +2,5 @@
 #define LLDB_VERSION_STRING "@LLDB_VERSION@"
 #define LLDB_VERSION_MAJOR @LLDB_VERSION_MAJOR@
 #define LLDB_VERSION_MINOR @LLDB_VERSION_MINOR@
-#define LLDB_VERSION_PATCHLEVEL @LLDB_VERSION_PATCHLEVEL@
+#define LLDB_VERSION_PATCH @LLDB_VERSION_PATCH@
 #cmakedefine LLDB_FULL_VERSION_STRING "@LLDB_FULL_VERSION_STRING@"


Index: llvm/utils/gn/secondary/lldb/include/lldb/Version/BUILD.gn
===
--- llvm/utils/gn/secondary/lldb/include/lldb/Version/BUILD.gn
+++ llvm/utils/gn/secondary/lldb/include/lldb/Version/BUILD.gn
@@ -9,7 +9,7 @@
 "LLDB_VERSION=$llvm_version",
 "LLDB_VERSION_MAJOR=$llvm_version_major",
 "LLDB_VERSION_MINOR=$llvm_version_minor",
-"LLDB_VERSION_PATCHLEVEL=$llvm_version_patch",
+"LLDB_VERSION_PATCH=$llvm_version_patch",
 "LLDB_FULL_VERSION_STRING=",
   ]
 }
Index: lldb/include/lldb/Version/Version.inc.in
===
--- lldb/include/lldb/Version/Version.inc.in
+++ lldb/include/lldb/Version/Version.inc.in
@@ -2,5 +2,5 @@
 #define LLDB_VERSION_STRING "@LLDB_VERSION@"
 #define LLDB_VERSION_MAJOR @LLDB_VERSION_MAJOR@
 #define LLDB_VERSION_MINOR @LLDB_VERSION_MINOR@
-#define LLDB_VERSION_PATCHLEVEL @LLDB_VERSION_PATCHLEVEL@
+#define LLDB_VERSION_PATCH @LLDB_VERSION_PATCH@
 #cmakedefine LLDB_FULL_VERSION_STRING "@LLDB_FULL_VERSION_STRING@"
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D147300: [lldb] Fix build on older FreeBSD

2023-03-31 Thread Dimitry Andric via Phabricator via lldb-commits
dim accepted this revision.
dim added a comment.
This revision is now accepted and ready to land.

LGTM, but if such SIGFPE's occur before the FPE_FLTIDO define was introduced, 
can they ever have value 9?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147300/new/

https://reviews.llvm.org/D147300

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


[Lldb-commits] [PATCH] D114465: [lldb] Move create_relative_symlink function up in CMake hierarchy

2021-11-23 Thread Dimitry Andric via Phabricator via lldb-commits
dim created this revision.
dim added reviewers: clayborg, emaste, labath, lawrence_danna, siger-young, 
tammela.
Herald added a subscriber: mgorny.
dim requested review of this revision.
Herald added a project: LLDB.

Configuring lldb with `LLDB_ENABLE_PYTHON=OFF` and `LLDB_ENABLE_LUA=ON` results 
in a CMake error:

  CMake Error at lldb/bindings/lua/CMakeLists.txt:47 (create_relative_symlink):
Unknown CMake command "create_relative_symlink".
  Call Stack (most recent call first):
lldb/CMakeLists.txt:117 (finish_swig_lua)

This is because the CMake function `create_relative_symlink` only exists in 
`lldb/bindings/python/CMakeLists.txt`, and not in 
`lldb/bindings/lua/CMakeLists.txt`.

Move the function to `lldb/bindings/CMakeLists.txt`, so it is available for all 
language bindings.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114465

Files:
  lldb/bindings/CMakeLists.txt
  lldb/bindings/python/CMakeLists.txt


Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -52,20 +52,6 @@
 WORKING_DIRECTORY ${working_dir})
 endfunction()
 
-function(create_relative_symlink swig_target dest_file output_dir output_name)
-  get_filename_component(dest_file ${dest_file} ABSOLUTE)
-  get_filename_component(output_dir ${output_dir} ABSOLUTE)
-  file(RELATIVE_PATH rel_dest_file ${output_dir} ${dest_file})
-  if(CMAKE_HOST_UNIX)
-set(LLVM_LINK_OR_COPY create_symlink)
-  else()
-set(LLVM_LINK_OR_COPY copy)
-  endif()
-  add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
-COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} ${rel_dest_file} 
${output_name}
-WORKING_DIRECTORY ${output_dir})
-endfunction()
-
 function(finish_swig_python swig_target lldb_python_bindings_dir 
lldb_python_target_dir)
   # Add a Post-Build Event to copy over Python files and create the symlink to
   # liblldb.so for the Python API(hardlink on Windows).
Index: lldb/bindings/CMakeLists.txt
===
--- lldb/bindings/CMakeLists.txt
+++ lldb/bindings/CMakeLists.txt
@@ -31,6 +31,20 @@
   ${DARWIN_EXTRAS}
 )
 
+function(create_relative_symlink swig_target dest_file output_dir output_name)
+  get_filename_component(dest_file ${dest_file} ABSOLUTE)
+  get_filename_component(output_dir ${output_dir} ABSOLUTE)
+  file(RELATIVE_PATH rel_dest_file ${output_dir} ${dest_file})
+  if(CMAKE_HOST_UNIX)
+set(LLVM_LINK_OR_COPY create_symlink)
+  else()
+set(LLVM_LINK_OR_COPY copy)
+  endif()
+  add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
+COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} ${rel_dest_file} 
${output_name}
+WORKING_DIRECTORY ${output_dir})
+endfunction()
+
 if (LLDB_ENABLE_PYTHON)
   add_subdirectory(python)
 endif()


Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -52,20 +52,6 @@
 WORKING_DIRECTORY ${working_dir})
 endfunction()
 
-function(create_relative_symlink swig_target dest_file output_dir output_name)
-  get_filename_component(dest_file ${dest_file} ABSOLUTE)
-  get_filename_component(output_dir ${output_dir} ABSOLUTE)
-  file(RELATIVE_PATH rel_dest_file ${output_dir} ${dest_file})
-  if(CMAKE_HOST_UNIX)
-set(LLVM_LINK_OR_COPY create_symlink)
-  else()
-set(LLVM_LINK_OR_COPY copy)
-  endif()
-  add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
-COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} ${rel_dest_file} ${output_name}
-WORKING_DIRECTORY ${output_dir})
-endfunction()
-
 function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_target_dir)
   # Add a Post-Build Event to copy over Python files and create the symlink to
   # liblldb.so for the Python API(hardlink on Windows).
Index: lldb/bindings/CMakeLists.txt
===
--- lldb/bindings/CMakeLists.txt
+++ lldb/bindings/CMakeLists.txt
@@ -31,6 +31,20 @@
   ${DARWIN_EXTRAS}
 )
 
+function(create_relative_symlink swig_target dest_file output_dir output_name)
+  get_filename_component(dest_file ${dest_file} ABSOLUTE)
+  get_filename_component(output_dir ${output_dir} ABSOLUTE)
+  file(RELATIVE_PATH rel_dest_file ${output_dir} ${dest_file})
+  if(CMAKE_HOST_UNIX)
+set(LLVM_LINK_OR_COPY create_symlink)
+  else()
+set(LLVM_LINK_OR_COPY copy)
+  endif()
+  add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
+COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} ${rel_dest_file} ${output_name}
+WORKING_DIRECTORY ${output_dir})
+endfunction()
+
 if (LLDB_ENABLE_PYTHON)
   add_subdirectory(python)
 endif()
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/list

[Lldb-commits] [PATCH] D114465: [lldb] Move create_relative_symlink function up in CMake hierarchy

2021-11-23 Thread Dimitry Andric via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb5a927b972b2: [lldb] Move create_relative_symlink function 
up in CMake hierarchy (authored by dim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114465/new/

https://reviews.llvm.org/D114465

Files:
  lldb/bindings/CMakeLists.txt
  lldb/bindings/python/CMakeLists.txt


Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -52,20 +52,6 @@
 WORKING_DIRECTORY ${working_dir})
 endfunction()
 
-function(create_relative_symlink swig_target dest_file output_dir output_name)
-  get_filename_component(dest_file ${dest_file} ABSOLUTE)
-  get_filename_component(output_dir ${output_dir} ABSOLUTE)
-  file(RELATIVE_PATH rel_dest_file ${output_dir} ${dest_file})
-  if(CMAKE_HOST_UNIX)
-set(LLVM_LINK_OR_COPY create_symlink)
-  else()
-set(LLVM_LINK_OR_COPY copy)
-  endif()
-  add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
-COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} ${rel_dest_file} 
${output_name}
-WORKING_DIRECTORY ${output_dir})
-endfunction()
-
 function(finish_swig_python swig_target lldb_python_bindings_dir 
lldb_python_target_dir)
   # Add a Post-Build Event to copy over Python files and create the symlink to
   # liblldb.so for the Python API(hardlink on Windows).
Index: lldb/bindings/CMakeLists.txt
===
--- lldb/bindings/CMakeLists.txt
+++ lldb/bindings/CMakeLists.txt
@@ -31,6 +31,20 @@
   ${DARWIN_EXTRAS}
 )
 
+function(create_relative_symlink swig_target dest_file output_dir output_name)
+  get_filename_component(dest_file ${dest_file} ABSOLUTE)
+  get_filename_component(output_dir ${output_dir} ABSOLUTE)
+  file(RELATIVE_PATH rel_dest_file ${output_dir} ${dest_file})
+  if(CMAKE_HOST_UNIX)
+set(LLVM_LINK_OR_COPY create_symlink)
+  else()
+set(LLVM_LINK_OR_COPY copy)
+  endif()
+  add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
+COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} ${rel_dest_file} 
${output_name}
+WORKING_DIRECTORY ${output_dir})
+endfunction()
+
 if (LLDB_ENABLE_PYTHON)
   add_subdirectory(python)
 endif()


Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -52,20 +52,6 @@
 WORKING_DIRECTORY ${working_dir})
 endfunction()
 
-function(create_relative_symlink swig_target dest_file output_dir output_name)
-  get_filename_component(dest_file ${dest_file} ABSOLUTE)
-  get_filename_component(output_dir ${output_dir} ABSOLUTE)
-  file(RELATIVE_PATH rel_dest_file ${output_dir} ${dest_file})
-  if(CMAKE_HOST_UNIX)
-set(LLVM_LINK_OR_COPY create_symlink)
-  else()
-set(LLVM_LINK_OR_COPY copy)
-  endif()
-  add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
-COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} ${rel_dest_file} ${output_name}
-WORKING_DIRECTORY ${output_dir})
-endfunction()
-
 function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_target_dir)
   # Add a Post-Build Event to copy over Python files and create the symlink to
   # liblldb.so for the Python API(hardlink on Windows).
Index: lldb/bindings/CMakeLists.txt
===
--- lldb/bindings/CMakeLists.txt
+++ lldb/bindings/CMakeLists.txt
@@ -31,6 +31,20 @@
   ${DARWIN_EXTRAS}
 )
 
+function(create_relative_symlink swig_target dest_file output_dir output_name)
+  get_filename_component(dest_file ${dest_file} ABSOLUTE)
+  get_filename_component(output_dir ${output_dir} ABSOLUTE)
+  file(RELATIVE_PATH rel_dest_file ${output_dir} ${dest_file})
+  if(CMAKE_HOST_UNIX)
+set(LLVM_LINK_OR_COPY create_symlink)
+  else()
+set(LLVM_LINK_OR_COPY copy)
+  endif()
+  add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
+COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} ${rel_dest_file} ${output_name}
+WORKING_DIRECTORY ${output_dir})
+endfunction()
+
 if (LLDB_ENABLE_PYTHON)
   add_subdirectory(python)
 endif()
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D101406: Rename human-readable name for DW_LANG_Mips_Assembler

2021-08-14 Thread Dimitry Andric via Phabricator via lldb-commits
dim added a comment.

Hmm so now on FreeBSD, basically *every* program will cause this warning, as 
our C startup objects are compiled from .S files, e.g.:

  % objdump --dwarf /bin/sleep|grep -B6 "MIPS assembler"
   <0><619>: Abbrev Number: 1 (DW_TAG_compile_unit)
  <61a>   DW_AT_stmt_list   : 0x3f1
  <61e>   DW_AT_ranges  : 0x30
  <622>   DW_AT_name: /usr/src/lib/csu/amd64/crti.S
  <640>   DW_AT_comp_dir: /usr/obj/usr/src/amd64.amd64/lib/csu/amd64
  <66b>   DW_AT_producer: FreeBSD clang version 12.0.1 
(g...@github.com:llvm/llvm-project.git llvmorg-12.0.1-0-gfed41342a82f)
  <6ce>   DW_AT_language: 32769   (MIPS assembler)
  --
   <0>: Abbrev Number: 1 (DW_TAG_compile_unit)
 DW_AT_stmt_list   : 0x93a
 DW_AT_ranges  : 0xb0
 DW_AT_name: /usr/src/lib/csu/amd64/crtn.S
 DW_AT_comp_dir: /usr/obj/usr/src/amd64.amd64/lib/csu/amd64
 DW_AT_producer: FreeBSD clang version 12.0.1 
(g...@github.com:llvm/llvm-project.git llvmorg-12.0.1-0-gfed41342a82f)
 DW_AT_language: 32769   (MIPS assembler)
  
  % lldb /bin/sleep 10
  (lldb) target create "/bin/sleep"
  Current executable set to '/bin/sleep' (x86_64).
  (lldb) settings set -- target.run-args  "10"
  (lldb) r
  Process 11879 launched: '/bin/sleep' (x86_64)
  This version of LLDB has no plugin for the mipsassem language. Inspection of 
frame variables will be limited.
  Process 11879 stopped
  * thread #1, name = 'sleep', stop reason = signal SIGSTOP
  frame #0: 0x0008011a610a libc.so.7`__sys_nanosleep at _nanosleep.S:4

This can't have been the intention of this commit? As far as  I can see, there 
*is* no plugin for plain assembler?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101406/new/

https://reviews.llvm.org/D101406

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


[Lldb-commits] [PATCH] D108088: [lldb] Avoid unhandled Error in TypeSystemMap::GetTypeSystemForLanguage

2021-08-15 Thread Dimitry Andric via Phabricator via lldb-commits
dim created this revision.
dim added reviewers: aprantl, emaste, JDevlieghere, teemperor.
Herald added subscribers: krytarowski, arichardson.
dim requested review of this revision.
Herald added a project: LLDB.

When assertions are turned off, the `llvm::Error` value created at the
start of this function is overwritten using the move-assignment
operator, but the success value is never checked. Whenever a TypeSystem
cannot be found or created, this can lead to lldb core dumping with:

  Program aborted due to an unhandled Error:
  Error value was Success. (Note: Success values must still be checked prior to 
being destroyed).

Fix this by not creating a `llvm::Error` value in advance, and directly
returning the result of `llvm::make_error` instead, whenever an error is
encountered.

See also: https://bugs.freebsd.org/253881 and
https://bugs.freebsd.org/257829.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108088

Files:
  lldb/source/Symbol/TypeSystem.cpp

Index: lldb/source/Symbol/TypeSystem.cpp
===
--- lldb/source/Symbol/TypeSystem.cpp
+++ lldb/source/Symbol/TypeSystem.cpp
@@ -223,62 +223,32 @@
 llvm::Expected TypeSystemMap::GetTypeSystemForLanguage(
 lldb::LanguageType language,
 llvm::Optional create_callback) {
-  llvm::Error error = llvm::Error::success();
-  assert(!error); // Check the success value when assertions are enabled
   std::lock_guard guard(m_mutex);
-  if (m_clear_in_progress) {
-error = llvm::make_error(
+  if (m_clear_in_progress)
+return llvm::make_error(
 "Unable to get TypeSystem because TypeSystemMap is being cleared",
 llvm::inconvertibleErrorCode());
-  } else {
-collection::iterator pos = m_map.find(language);
-if (pos != m_map.end()) {
-  auto *type_system = pos->second.get();
-  if (type_system) {
-llvm::consumeError(std::move(error));
-return *type_system;
-  }
-  error = llvm::make_error(
-  "TypeSystem for language " +
-  llvm::StringRef(Language::GetNameForLanguageType(language)) +
-  " doesn't exist",
-  llvm::inconvertibleErrorCode());
-  return std::move(error);
-}
 
-for (const auto &pair : m_map) {
-  if (pair.second && pair.second->SupportsLanguage(language)) {
-// Add a new mapping for "language" to point to an already existing
-// TypeSystem that supports this language
-m_map[language] = pair.second;
-if (pair.second.get()) {
-  llvm::consumeError(std::move(error));
-  return *pair.second.get();
-}
-error = llvm::make_error(
-"TypeSystem for language " +
-llvm::StringRef(Language::GetNameForLanguageType(language)) +
-" doesn't exist",
-llvm::inconvertibleErrorCode());
-return std::move(error);
-  }
-}
+  collection::iterator pos = m_map.find(language);
+  if (pos != m_map.end()) {
+auto *type_system = pos->second.get();
+if (type_system)
+  return *type_system;
+return llvm::make_error(
+"TypeSystem for language " +
+llvm::StringRef(Language::GetNameForLanguageType(language)) +
+" doesn't exist",
+llvm::inconvertibleErrorCode());
+  }
 
-if (!create_callback) {
-  error = llvm::make_error(
-  "Unable to find type system for language " +
-  llvm::StringRef(Language::GetNameForLanguageType(language)),
-  llvm::inconvertibleErrorCode());
-} else {
-  // Cache even if we get a shared pointer that contains a null type system
-  // back
-  TypeSystemSP type_system_sp = (*create_callback)();
-  m_map[language] = type_system_sp;
-  if (type_system_sp.get()) {
-llvm::consumeError(std::move(error));
-return *type_system_sp.get();
-  }
-  error = llvm::make_error(
+  for (const auto &pair : m_map) {
+if (pair.second && pair.second->SupportsLanguage(language)) {
+  // Add a new mapping for "language" to point to an already existing
+  // TypeSystem that supports this language
+  m_map[language] = pair.second;
+  if (pair.second.get())
+return *pair.second.get();
+  return llvm::make_error(
   "TypeSystem for language " +
   llvm::StringRef(Language::GetNameForLanguageType(language)) +
   " doesn't exist",
@@ -286,7 +256,23 @@
 }
   }
 
-  return std::move(error);
+  if (!create_callback)
+return llvm::make_error(
+"Unable to find type system for language " +
+llvm::StringRef(Language::GetNameForLanguageType(language)),
+llvm::inconvertibleErrorCode());
+
+  // Cache even if we get a shared pointer that contains a null type system
+  // back
+  TypeSystemSP type_system_sp = (*create_callback)();
+  m_map[language] = type_system_sp;
+  if (type_system_sp.get())
+return *type_system_sp.get();
+  re

[Lldb-commits] [PATCH] D108088: [lldb] Avoid unhandled Error in TypeSystemMap::GetTypeSystemForLanguage

2021-08-16 Thread Dimitry Andric via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5033f0793fe6: [lldb] Avoid unhandled Error in 
TypeSystemMap::GetTypeSystemForLanguage (authored by dim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108088/new/

https://reviews.llvm.org/D108088

Files:
  lldb/source/Symbol/TypeSystem.cpp

Index: lldb/source/Symbol/TypeSystem.cpp
===
--- lldb/source/Symbol/TypeSystem.cpp
+++ lldb/source/Symbol/TypeSystem.cpp
@@ -223,62 +223,32 @@
 llvm::Expected TypeSystemMap::GetTypeSystemForLanguage(
 lldb::LanguageType language,
 llvm::Optional create_callback) {
-  llvm::Error error = llvm::Error::success();
-  assert(!error); // Check the success value when assertions are enabled
   std::lock_guard guard(m_mutex);
-  if (m_clear_in_progress) {
-error = llvm::make_error(
+  if (m_clear_in_progress)
+return llvm::make_error(
 "Unable to get TypeSystem because TypeSystemMap is being cleared",
 llvm::inconvertibleErrorCode());
-  } else {
-collection::iterator pos = m_map.find(language);
-if (pos != m_map.end()) {
-  auto *type_system = pos->second.get();
-  if (type_system) {
-llvm::consumeError(std::move(error));
-return *type_system;
-  }
-  error = llvm::make_error(
-  "TypeSystem for language " +
-  llvm::StringRef(Language::GetNameForLanguageType(language)) +
-  " doesn't exist",
-  llvm::inconvertibleErrorCode());
-  return std::move(error);
-}
 
-for (const auto &pair : m_map) {
-  if (pair.second && pair.second->SupportsLanguage(language)) {
-// Add a new mapping for "language" to point to an already existing
-// TypeSystem that supports this language
-m_map[language] = pair.second;
-if (pair.second.get()) {
-  llvm::consumeError(std::move(error));
-  return *pair.second.get();
-}
-error = llvm::make_error(
-"TypeSystem for language " +
-llvm::StringRef(Language::GetNameForLanguageType(language)) +
-" doesn't exist",
-llvm::inconvertibleErrorCode());
-return std::move(error);
-  }
-}
+  collection::iterator pos = m_map.find(language);
+  if (pos != m_map.end()) {
+auto *type_system = pos->second.get();
+if (type_system)
+  return *type_system;
+return llvm::make_error(
+"TypeSystem for language " +
+llvm::StringRef(Language::GetNameForLanguageType(language)) +
+" doesn't exist",
+llvm::inconvertibleErrorCode());
+  }
 
-if (!create_callback) {
-  error = llvm::make_error(
-  "Unable to find type system for language " +
-  llvm::StringRef(Language::GetNameForLanguageType(language)),
-  llvm::inconvertibleErrorCode());
-} else {
-  // Cache even if we get a shared pointer that contains a null type system
-  // back
-  TypeSystemSP type_system_sp = (*create_callback)();
-  m_map[language] = type_system_sp;
-  if (type_system_sp.get()) {
-llvm::consumeError(std::move(error));
-return *type_system_sp.get();
-  }
-  error = llvm::make_error(
+  for (const auto &pair : m_map) {
+if (pair.second && pair.second->SupportsLanguage(language)) {
+  // Add a new mapping for "language" to point to an already existing
+  // TypeSystem that supports this language
+  m_map[language] = pair.second;
+  if (pair.second.get())
+return *pair.second.get();
+  return llvm::make_error(
   "TypeSystem for language " +
   llvm::StringRef(Language::GetNameForLanguageType(language)) +
   " doesn't exist",
@@ -286,7 +256,23 @@
 }
   }
 
-  return std::move(error);
+  if (!create_callback)
+return llvm::make_error(
+"Unable to find type system for language " +
+llvm::StringRef(Language::GetNameForLanguageType(language)),
+llvm::inconvertibleErrorCode());
+
+  // Cache even if we get a shared pointer that contains a null type system
+  // back
+  TypeSystemSP type_system_sp = (*create_callback)();
+  m_map[language] = type_system_sp;
+  if (type_system_sp.get())
+return *type_system_sp.get();
+  return llvm::make_error(
+  "TypeSystem for language " +
+  llvm::StringRef(Language::GetNameForLanguageType(language)) +
+  " doesn't exist",
+  llvm::inconvertibleErrorCode());
 }
 
 llvm::Expected
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D101406: Rename human-readable name for DW_LANG_Mips_Assembler

2021-08-17 Thread Dimitry Andric via Phabricator via lldb-commits
dim added a comment.

In D101406#2948152 , @clayborg wrote:

> Everyone uses this for any assembly in their code. Should we get rid of this 
> warning? I find it is useless and would like to see it go.

Well, for other languages it might be a helpful warning, but not for the 
special case of "mips" assembler. :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101406/new/

https://reviews.llvm.org/D101406

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


[Lldb-commits] [PATCH] D101406: Rename human-readable name for DW_LANG_Mips_Assembler

2021-08-19 Thread Dimitry Andric via Phabricator via lldb-commits
dim added a comment.

In D101406#2950731 , @aprantl wrote:

>> This can't have been the intention of this commit? As far as I can see, 
>> there *is* no plugin for plain assembler?

...

> Yes, there is no plugin for the language assembler. But that hasn't chnaged 
> with this commit.

Sorry, that was rG220c17ffd4e1b127bcc02b25980b7934184ee1da 
 ("Print a 
warning when stopped in a frame LLDB has no plugin for"), which is probably a 
good idea in general, but maybe there could be a specific exception for the 
DW_LANG_Mips_Assembler case then? It doesn't make sense to warn about that. :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101406/new/

https://reviews.llvm.org/D101406

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


[Lldb-commits] [PATCH] D86355: Consume error for valid return from Target::GetEntryPointAddress()

2020-08-21 Thread Dimitry Andric via Phabricator via lldb-commits
dim created this revision.
dim added reviewers: aprantl, emaste, JDevlieghere, jingham.
Herald added subscribers: krytarowski, arichardson.
Herald added a project: LLDB.
dim requested review of this revision.

When `Target::GetEntryPointAddress()` calls
`exe_module->GetObjectFile()->GetEntryPointAddress()`, and the returned
`entry_addr` is valid, it can immediately be returned.

However, just before that, an `llvm::Error` value has been setup, but in
this case it is not consumed before returning, like is done further
below in the function.

In https://bugs.freebsd.org/248745 we got a bug report for this, where a
very simple test case aborts and dumps core:

  * thread #1, name = 'testcase', stop reason = breakpoint 1.1
  frame #0: 0x002018d4 testcase`main(argc=1, 
argv=0x7fffea18) at testcase.c:3:5
 1  int main(int argc, char *argv[])
 2  {
  -> 3  return 0;
 4  }
  (lldb) p argc
  Program aborted due to an unhandled Error:
  Error value was Success. (Note: Success values must still be checked prior to 
being destroyed).
  
  Thread 1 received signal SIGABRT, Aborted.
  thr_kill () at thr_kill.S:3
  3 thr_kill.S: No such file or directory.
  (gdb) bt
  #0  thr_kill () at thr_kill.S:3
  #1  0x0008049a0004 in __raise (s=6) at /usr/src/lib/libc/gen/raise.c:52
  #2  0x000804916229 in abort () at /usr/src/lib/libc/stdlib/abort.c:67
  #3  0x0451b5f5 in fatalUncheckedError () at 
/usr/src/contrib/llvm-project/llvm/lib/Support/Error.cpp:112
  #4  0x019cf008 in GetEntryPointAddress () at 
/usr/src/contrib/llvm-project/llvm/include/llvm/Support/Error.h:267
  #5  0x01bccbd8 in ConstructorSetup () at 
/usr/src/contrib/llvm-project/lldb/source/Target/ThreadPlanCallFunction.cpp:67
  #6  0x01bcd2c0 in ThreadPlanCallFunction () at 
/usr/src/contrib/llvm-project/lldb/source/Target/ThreadPlanCallFunction.cpp:114
  #7  0x020076d4 in InferiorCallMmap () at 
/usr/src/contrib/llvm-project/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp:97
  #8  0x01f4be33 in DoAllocateMemory () at 
/usr/src/contrib/llvm-project/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp:604
  #9  0x01fe51b9 in AllocatePage () at 
/usr/src/contrib/llvm-project/lldb/source/Target/Memory.cpp:347
  #10 0x01fe5385 in AllocateMemory () at 
/usr/src/contrib/llvm-project/lldb/source/Target/Memory.cpp:383
  #11 0x01974da2 in AllocateMemory () at 
/usr/src/contrib/llvm-project/lldb/source/Target/Process.cpp:2301
  #12 CanJIT () at 
/usr/src/contrib/llvm-project/lldb/source/Target/Process.cpp:2331
  #13 0x01a1bf3d in Evaluate () at 
/usr/src/contrib/llvm-project/lldb/source/Expression/UserExpression.cpp:190
  #14 0x019ce7a2 in EvaluateExpression () at 
/usr/src/contrib/llvm-project/lldb/source/Target/Target.cpp:2372
  #15 0x01ad784c in EvaluateExpression () at 
/usr/src/contrib/llvm-project/lldb/source/Commands/CommandObjectExpression.cpp:414
  #16 0x01ad86ae in DoExecute () at 
/usr/src/contrib/llvm-project/lldb/source/Commands/CommandObjectExpression.cpp:646
  #17 0x01a5e3ed in Execute () at 
/usr/src/contrib/llvm-project/lldb/source/Interpreter/CommandObject.cpp:1003
  #18 0x01a6c4a3 in HandleCommand () at 
/usr/src/contrib/llvm-project/lldb/source/Interpreter/CommandInterpreter.cpp:1762
  #19 0x01a6f98c in IOHandlerInputComplete () at 
/usr/src/contrib/llvm-project/lldb/source/Interpreter/CommandInterpreter.cpp:2760
  #20 0x01a90b08 in Run () at 
/usr/src/contrib/llvm-project/lldb/source/Core/IOHandler.cpp:548
  #21 0x019a6c6a in ExecuteIOHandlers () at 
/usr/src/contrib/llvm-project/lldb/source/Core/Debugger.cpp:903
  #22 0x01a70337 in RunCommandInterpreter () at 
/usr/src/contrib/llvm-project/lldb/source/Interpreter/CommandInterpreter.cpp:2946
  #23 0x01d9d812 in RunCommandInterpreter () at 
/usr/src/contrib/llvm-project/lldb/source/API/SBDebugger.cpp:1169
  #24 0x01918be8 in MainLoop () at 
/usr/src/contrib/llvm-project/lldb/tools/driver/Driver.cpp:675
  #25 0x0191a114 in main () at 
/usr/src/contrib/llvm-project/lldb/tools/driver/Driver.cpp:890

Fix the incorrect error catch by explicitly consuming the error, similar
to the `module_sp->GetObjectFile()->GetEntryPointAddress()` return path.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86355

Files:
  lldb/source/Target/Target.cpp


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -2415,8 +2415,11 @@
 
llvm::inconvertibleErrorCode());
   } else {
 Address entry_addr = exe_module->GetObjectFile()->GetEntryPointAddress();
-if (entry_addr.IsValid())
+if (entry_addr.IsValid()) {
+  // Discard the error.
+  llvm::consumeError(std::move(error));
   return entry_add

[Lldb-commits] [PATCH] D86355: Consume error for valid return from Target::GetEntryPointAddress()

2020-08-21 Thread Dimitry Andric via Phabricator via lldb-commits
dim added inline comments.



Comment at: lldb/source/Target/Target.cpp:2408-2446
 llvm::Expected Target::GetEntryPointAddress() {
   Module *exe_module = GetExecutableModulePointer();
   llvm::Error error = llvm::Error::success();
   assert(!error); // Check the success value when assertions are enabled.
 
   if (!exe_module || !exe_module->GetObjectFile()) {
 error = llvm::make_error("No primary executable found",

JDevlieghere wrote:
> I'm not particularly happy with the error handling in this function. The 
> patch seems correct, but as I've demonstrated it's easy to get this wrong. I 
> think we can rewrite the method as suggested to eliminate the issue. What do 
> you think?
Yeah, I think that is much less error-prone. The `consumeError` method has a 
relevent comment:

```
/// Uses of this method are potentially indicative of problems: perhaps the
/// error should be propagated further, or the error-producer should just
/// return an Optional in the first place.
```

In this case it was just problematic to instantiate an `Error` right at the 
start, instead of when an actual error condition occurred.

So I agree that your proposed approach is better. There is still one 
`consumeError()` in there, though?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86355/new/

https://reviews.llvm.org/D86355

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


[Lldb-commits] [PATCH] D86355: Consume error for valid return from Target::GetEntryPointAddress()

2020-08-21 Thread Dimitry Andric via Phabricator via lldb-commits
dim updated this revision to Diff 287077.
dim added a comment.

As @JDevlieghere suggests, only instantiate `Error` objects when necessary.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86355/new/

https://reviews.llvm.org/D86355

Files:
  lldb/source/Target/Target.cpp


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -2407,21 +2407,13 @@
 
 llvm::Expected Target::GetEntryPointAddress() {
   Module *exe_module = GetExecutableModulePointer();
-  llvm::Error error = llvm::Error::success();
-  assert(!error); // Check the success value when assertions are enabled.
 
-  if (!exe_module || !exe_module->GetObjectFile()) {
-error = llvm::make_error("No primary executable found",
-
llvm::inconvertibleErrorCode());
-  } else {
+  // Try to find the entry point address in the primary executable.
+  const bool has_primary_executable = exe_module && 
exe_module->GetObjectFile();
+  if (has_primary_executable) {
 Address entry_addr = exe_module->GetObjectFile()->GetEntryPointAddress();
 if (entry_addr.IsValid())
   return entry_addr;
-
-error = llvm::make_error(
-"Could not find entry point address for executable module \"" +
-exe_module->GetFileSpec().GetFilename().GetStringRef() + "\"",
-llvm::inconvertibleErrorCode());
   }
 
   const ModuleList &modules = GetImages();
@@ -2432,14 +2424,21 @@
   continue;
 
 Address entry_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
-if (entry_addr.IsValid()) {
-  // Discard the error.
-  llvm::consumeError(std::move(error));
+if (entry_addr.IsValid())
   return entry_addr;
-}
   }
 
-  return std::move(error);
+  // We haven't found the entry point address. Return an appropriate error.
+  if (!has_primary_executable)
+return llvm::make_error(
+"No primary executable found and could not find entry point address in 
"
+"any executable module",
+llvm::inconvertibleErrorCode());
+
+  return llvm::make_error(
+  "Could not find entry point address for primary executable module \"" +
+  exe_module->GetFileSpec().GetFilename().GetStringRef() + "\"",
+  llvm::inconvertibleErrorCode());
 }
 
 lldb::addr_t Target::GetCallableLoadAddress(lldb::addr_t load_addr,


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -2407,21 +2407,13 @@
 
 llvm::Expected Target::GetEntryPointAddress() {
   Module *exe_module = GetExecutableModulePointer();
-  llvm::Error error = llvm::Error::success();
-  assert(!error); // Check the success value when assertions are enabled.
 
-  if (!exe_module || !exe_module->GetObjectFile()) {
-error = llvm::make_error("No primary executable found",
-llvm::inconvertibleErrorCode());
-  } else {
+  // Try to find the entry point address in the primary executable.
+  const bool has_primary_executable = exe_module && exe_module->GetObjectFile();
+  if (has_primary_executable) {
 Address entry_addr = exe_module->GetObjectFile()->GetEntryPointAddress();
 if (entry_addr.IsValid())
   return entry_addr;
-
-error = llvm::make_error(
-"Could not find entry point address for executable module \"" +
-exe_module->GetFileSpec().GetFilename().GetStringRef() + "\"",
-llvm::inconvertibleErrorCode());
   }
 
   const ModuleList &modules = GetImages();
@@ -2432,14 +2424,21 @@
   continue;
 
 Address entry_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
-if (entry_addr.IsValid()) {
-  // Discard the error.
-  llvm::consumeError(std::move(error));
+if (entry_addr.IsValid())
   return entry_addr;
-}
   }
 
-  return std::move(error);
+  // We haven't found the entry point address. Return an appropriate error.
+  if (!has_primary_executable)
+return llvm::make_error(
+"No primary executable found and could not find entry point address in "
+"any executable module",
+llvm::inconvertibleErrorCode());
+
+  return llvm::make_error(
+  "Could not find entry point address for primary executable module \"" +
+  exe_module->GetFileSpec().GetFilename().GetStringRef() + "\"",
+  llvm::inconvertibleErrorCode());
 }
 
 lldb::addr_t Target::GetCallableLoadAddress(lldb::addr_t load_addr,
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D86355: Instantiate Error in Target::GetEntryPointAddress() only when necessary

2020-08-22 Thread Dimitry Andric via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1ce07cd614be: Instantiate Error in 
Target::GetEntryPointAddress() only when necessary (authored by dim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86355/new/

https://reviews.llvm.org/D86355

Files:
  lldb/source/Target/Target.cpp


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -2407,21 +2407,13 @@
 
 llvm::Expected Target::GetEntryPointAddress() {
   Module *exe_module = GetExecutableModulePointer();
-  llvm::Error error = llvm::Error::success();
-  assert(!error); // Check the success value when assertions are enabled.
 
-  if (!exe_module || !exe_module->GetObjectFile()) {
-error = llvm::make_error("No primary executable found",
-
llvm::inconvertibleErrorCode());
-  } else {
+  // Try to find the entry point address in the primary executable.
+  const bool has_primary_executable = exe_module && 
exe_module->GetObjectFile();
+  if (has_primary_executable) {
 Address entry_addr = exe_module->GetObjectFile()->GetEntryPointAddress();
 if (entry_addr.IsValid())
   return entry_addr;
-
-error = llvm::make_error(
-"Could not find entry point address for executable module \"" +
-exe_module->GetFileSpec().GetFilename().GetStringRef() + "\"",
-llvm::inconvertibleErrorCode());
   }
 
   const ModuleList &modules = GetImages();
@@ -2432,14 +2424,21 @@
   continue;
 
 Address entry_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
-if (entry_addr.IsValid()) {
-  // Discard the error.
-  llvm::consumeError(std::move(error));
+if (entry_addr.IsValid())
   return entry_addr;
-}
   }
 
-  return std::move(error);
+  // We haven't found the entry point address. Return an appropriate error.
+  if (!has_primary_executable)
+return llvm::make_error(
+"No primary executable found and could not find entry point address in 
"
+"any executable module",
+llvm::inconvertibleErrorCode());
+
+  return llvm::make_error(
+  "Could not find entry point address for primary executable module \"" +
+  exe_module->GetFileSpec().GetFilename().GetStringRef() + "\"",
+  llvm::inconvertibleErrorCode());
 }
 
 lldb::addr_t Target::GetCallableLoadAddress(lldb::addr_t load_addr,


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -2407,21 +2407,13 @@
 
 llvm::Expected Target::GetEntryPointAddress() {
   Module *exe_module = GetExecutableModulePointer();
-  llvm::Error error = llvm::Error::success();
-  assert(!error); // Check the success value when assertions are enabled.
 
-  if (!exe_module || !exe_module->GetObjectFile()) {
-error = llvm::make_error("No primary executable found",
-llvm::inconvertibleErrorCode());
-  } else {
+  // Try to find the entry point address in the primary executable.
+  const bool has_primary_executable = exe_module && exe_module->GetObjectFile();
+  if (has_primary_executable) {
 Address entry_addr = exe_module->GetObjectFile()->GetEntryPointAddress();
 if (entry_addr.IsValid())
   return entry_addr;
-
-error = llvm::make_error(
-"Could not find entry point address for executable module \"" +
-exe_module->GetFileSpec().GetFilename().GetStringRef() + "\"",
-llvm::inconvertibleErrorCode());
   }
 
   const ModuleList &modules = GetImages();
@@ -2432,14 +2424,21 @@
   continue;
 
 Address entry_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
-if (entry_addr.IsValid()) {
-  // Discard the error.
-  llvm::consumeError(std::move(error));
+if (entry_addr.IsValid())
   return entry_addr;
-}
   }
 
-  return std::move(error);
+  // We haven't found the entry point address. Return an appropriate error.
+  if (!has_primary_executable)
+return llvm::make_error(
+"No primary executable found and could not find entry point address in "
+"any executable module",
+llvm::inconvertibleErrorCode());
+
+  return llvm::make_error(
+  "Could not find entry point address for primary executable module \"" +
+  exe_module->GetFileSpec().GetFilename().GetStringRef() + "\"",
+  llvm::inconvertibleErrorCode());
 }
 
 lldb::addr_t Target::GetCallableLoadAddress(lldb::addr_t load_addr,
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D68723: Fix process launch failure on FreeBSD after r365761

2019-10-09 Thread Dimitry Andric via Phabricator via lldb-commits
dim created this revision.
dim added reviewers: devnexen, emaste, MaskRay, mgorny.
Herald added a subscriber: krytarowski.
dim added a comment.

After rLLDB365761 , and with 
`LLVM_ENABLE_ABI_BREAKING_CHECKS` enabled, launching
any process on FreeBSD crashes lldb with:

  Expected must be checked before access or destruction.
  Expected value was in success state. (Note: Expected values in success 
mode must still be checked prior to being destroyed).

This is because `m_operation_thread` and `m_monitor_thread` were wrapped in
`llvm::Expected<>`, but this requires the objects to be correctly initialized
before accessing them.

To fix the crashes, revert the wrapping, and use local variables to store the
return values of `LaunchThread` and `StartMonitoringChildProcess`.  Then, only
assign to the member variables after checking if the return values indicated
success.


https://reviews.llvm.org/D68723

Files:
  source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
  source/Plugins/Process/FreeBSD/ProcessMonitor.h

Index: source/Plugins/Process/FreeBSD/ProcessMonitor.h
===
--- source/Plugins/Process/FreeBSD/ProcessMonitor.h
+++ source/Plugins/Process/FreeBSD/ProcessMonitor.h
@@ -183,8 +183,8 @@
 private:
   ProcessFreeBSD *m_process;
 
-  llvm::Expected m_operation_thread;
-  llvm::Expected m_monitor_thread;
+  lldb_private::HostThread m_operation_thread;
+  lldb_private::HostThread m_monitor_thread;
   lldb::pid_t m_pid;
 
   int m_terminal_fd;
Index: source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
===
--- source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
+++ source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
@@ -703,7 +703,7 @@
 const lldb_private::ProcessLaunchInfo & /* launch_info */,
 lldb_private::Status &error)
 : m_process(static_cast(process)),
-  m_operation_thread(nullptr), m_monitor_thread(nullptr), m_pid(LLDB_INVALID_PROCESS_ID), m_terminal_fd(-1), m_operation(0) {
+  m_operation_thread(), m_monitor_thread(), m_pid(LLDB_INVALID_PROCESS_ID), m_terminal_fd(-1), m_operation(0) {
   using namespace std::placeholders;
 
   std::unique_ptr args(
@@ -730,20 +730,21 @@
   }
 
   // Finally, start monitoring the child process for change in state.
-  m_monitor_thread = Host::StartMonitoringChildProcess(
+  auto monitor_thread = Host::StartMonitoringChildProcess(
   std::bind(&ProcessMonitor::MonitorCallback, this, _1, _2, _3, _4),
   GetPID(), true);
-  if (!m_monitor_thread->IsJoinable()) {
+  if (!monitor_thread || !monitor_thread->IsJoinable()) {
 error.SetErrorToGenericError();
 error.SetErrorString("Process launch failed.");
 return;
   }
+  m_monitor_thread = *monitor_thread;
 }
 
 ProcessMonitor::ProcessMonitor(ProcessFreeBSD *process, lldb::pid_t pid,
lldb_private::Status &error)
 : m_process(static_cast(process)),
-  m_operation_thread(nullptr), m_monitor_thread(nullptr), m_pid(pid), m_terminal_fd(-1), m_operation(0) {
+  m_operation_thread(), m_monitor_thread(), m_pid(pid), m_terminal_fd(-1), m_operation(0) {
   using namespace std::placeholders;
 
   sem_init(&m_operation_pending, 0, 0);
@@ -768,14 +769,15 @@
   }
 
   // Finally, start monitoring the child process for change in state.
-  m_monitor_thread = Host::StartMonitoringChildProcess(
+  auto monitor_thread = Host::StartMonitoringChildProcess(
   std::bind(&ProcessMonitor::MonitorCallback, this, _1, _2, _3, _4),
   GetPID(), true);
-  if (!m_monitor_thread->IsJoinable()) {
+  if (!monitor_thread || !monitor_thread->IsJoinable()) {
 error.SetErrorToGenericError();
 error.SetErrorString("Process attach failed.");
 return;
   }
+  m_monitor_thread = *monitor_thread;
 }
 
 ProcessMonitor::~ProcessMonitor() { StopMonitor(); }
@@ -784,13 +786,15 @@
 void ProcessMonitor::StartLaunchOpThread(LaunchArgs *args, Status &error) {
   static const char *g_thread_name = "lldb.process.freebsd.operation";
 
-  if (m_operation_thread->IsJoinable())
+  if (m_operation_thread.IsJoinable())
 return;
 
-  m_operation_thread =
+  auto operation_thread =
   ThreadLauncher::LaunchThread(g_thread_name, LaunchOpThread, args);
-  if (!m_operation_thread)
- error = m_operation_thread.takeError();
+  if (operation_thread)
+m_operation_thread = *operation_thread;
+  else
+error = operation_thread.takeError();
 }
 
 void *ProcessMonitor::LaunchOpThread(void *arg) {
@@ -952,14 +956,15 @@
  lldb_private::Status &error) {
   static const char *g_thread_name = "lldb.process.freebsd.operation";
 
-  if (m_operation_thread->IsJoinable())
+  if (m_operation_thread.IsJoinable())
 return;
 
-  m_operation_thread =
+  auto operation_thread =
   ThreadLauncher::LaunchThread(g_thread_name, AttachOpThread, args);
-
-  if (!m_operation_thread)
-	error = m_

[Lldb-commits] [PATCH] D68723: Fix process launch failure on FreeBSD after r365761

2019-10-09 Thread Dimitry Andric via Phabricator via lldb-commits
dim added a comment.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68723/new/

https://reviews.llvm.org/D68723



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


[Lldb-commits] [PATCH] D68723: Fix process launch failure on FreeBSD after r365761

2019-10-10 Thread Dimitry Andric via Phabricator via lldb-commits
dim updated this revision to Diff 224447.
dim added a comment.
Herald added a subscriber: jfb.

Convert `m_(monitor|operation)_thread` to `llvm::Optional<>`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68723/new/

https://reviews.llvm.org/D68723

Files:
  source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
  source/Plugins/Process/FreeBSD/ProcessMonitor.h

Index: source/Plugins/Process/FreeBSD/ProcessMonitor.h
===
--- source/Plugins/Process/FreeBSD/ProcessMonitor.h
+++ source/Plugins/Process/FreeBSD/ProcessMonitor.h
@@ -183,8 +183,8 @@
 private:
   ProcessFreeBSD *m_process;
 
-  llvm::Expected m_operation_thread;
-  llvm::Expected m_monitor_thread;
+  llvm::Optional m_operation_thread;
+  llvm::Optional m_monitor_thread;
   lldb::pid_t m_pid;
 
   int m_terminal_fd;
Index: source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
===
--- source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
+++ source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
@@ -703,7 +703,7 @@
 const lldb_private::ProcessLaunchInfo & /* launch_info */,
 lldb_private::Status &error)
 : m_process(static_cast(process)),
-  m_operation_thread(nullptr), m_monitor_thread(nullptr), m_pid(LLDB_INVALID_PROCESS_ID), m_terminal_fd(-1), m_operation(0) {
+  m_operation_thread(), m_monitor_thread(), m_pid(LLDB_INVALID_PROCESS_ID), m_terminal_fd(-1), m_operation(0) {
   using namespace std::placeholders;
 
   std::unique_ptr args(
@@ -730,20 +730,22 @@
   }
 
   // Finally, start monitoring the child process for change in state.
-  m_monitor_thread = Host::StartMonitoringChildProcess(
+  llvm::Expected monitor_thread =
+Host::StartMonitoringChildProcess(
   std::bind(&ProcessMonitor::MonitorCallback, this, _1, _2, _3, _4),
   GetPID(), true);
-  if (!m_monitor_thread->IsJoinable()) {
+  if (!monitor_thread || !monitor_thread->IsJoinable()) {
 error.SetErrorToGenericError();
 error.SetErrorString("Process launch failed.");
 return;
   }
+  m_monitor_thread = *monitor_thread;
 }
 
 ProcessMonitor::ProcessMonitor(ProcessFreeBSD *process, lldb::pid_t pid,
lldb_private::Status &error)
 : m_process(static_cast(process)),
-  m_operation_thread(nullptr), m_monitor_thread(nullptr), m_pid(pid), m_terminal_fd(-1), m_operation(0) {
+  m_operation_thread(), m_monitor_thread(), m_pid(pid), m_terminal_fd(-1), m_operation(0) {
   using namespace std::placeholders;
 
   sem_init(&m_operation_pending, 0, 0);
@@ -768,14 +770,16 @@
   }
 
   // Finally, start monitoring the child process for change in state.
-  m_monitor_thread = Host::StartMonitoringChildProcess(
+  llvm::Expected monitor_thread =
+Host::StartMonitoringChildProcess(
   std::bind(&ProcessMonitor::MonitorCallback, this, _1, _2, _3, _4),
   GetPID(), true);
-  if (!m_monitor_thread->IsJoinable()) {
+  if (!monitor_thread || !monitor_thread->IsJoinable()) {
 error.SetErrorToGenericError();
 error.SetErrorString("Process attach failed.");
 return;
   }
+  m_monitor_thread = *monitor_thread;
 }
 
 ProcessMonitor::~ProcessMonitor() { StopMonitor(); }
@@ -784,13 +788,15 @@
 void ProcessMonitor::StartLaunchOpThread(LaunchArgs *args, Status &error) {
   static const char *g_thread_name = "lldb.process.freebsd.operation";
 
-  if (m_operation_thread->IsJoinable())
+  if (m_operation_thread && m_operation_thread->IsJoinable())
 return;
 
-  m_operation_thread =
-  ThreadLauncher::LaunchThread(g_thread_name, LaunchOpThread, args);
-  if (!m_operation_thread)
- error = m_operation_thread.takeError();
+  llvm::Expected operation_thread =
+ThreadLauncher::LaunchThread(g_thread_name, LaunchOpThread, args);
+  if (operation_thread)
+m_operation_thread = *operation_thread;
+  else
+error = operation_thread.takeError();
 }
 
 void *ProcessMonitor::LaunchOpThread(void *arg) {
@@ -952,14 +958,15 @@
  lldb_private::Status &error) {
   static const char *g_thread_name = "lldb.process.freebsd.operation";
 
-  if (m_operation_thread->IsJoinable())
+  if (m_operation_thread && m_operation_thread->IsJoinable())
 return;
 
-  m_operation_thread =
-  ThreadLauncher::LaunchThread(g_thread_name, AttachOpThread, args);
-
-  if (!m_operation_thread)
-	error = m_operation_thread.takeError();
+  llvm::Expected operation_thread =
+ThreadLauncher::LaunchThread(g_thread_name, AttachOpThread, args);
+  if (operation_thread)
+m_operation_thread = *operation_thread;
+  else
+error = operation_thread.takeError();
 }
 
 void *ProcessMonitor::AttachOpThread(void *arg) {
@@ -1374,7 +1381,7 @@
 }
 
 void ProcessMonitor::StopMonitoringChildProcess() {
-  if (m_monitor_thread->IsJoinable()) {
+  if (m_monitor_thread && m_monitor_thread->IsJoinable()) {
 m_monitor_thread->Cancel();
 m_monitor_thread->Join(nullptr);
 m_monit

[Lldb-commits] [PATCH] D68723: Fix process launch failure on FreeBSD after r365761

2019-10-10 Thread Dimitry Andric via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa42942e0ecd6: Fix process launch failure on FreeBSD after 
r365761 (authored by dim).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D68723?vs=224447&id=224460#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68723/new/

https://reviews.llvm.org/D68723

Files:
  lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
  lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h

Index: lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h
===
--- lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h
+++ lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h
@@ -183,8 +183,8 @@
 private:
   ProcessFreeBSD *m_process;
 
-  llvm::Expected m_operation_thread;
-  llvm::Expected m_monitor_thread;
+  llvm::Optional m_operation_thread;
+  llvm::Optional m_monitor_thread;
   lldb::pid_t m_pid;
 
   int m_terminal_fd;
Index: lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
===
--- lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
+++ lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
@@ -703,7 +703,7 @@
 const lldb_private::ProcessLaunchInfo & /* launch_info */,
 lldb_private::Status &error)
 : m_process(static_cast(process)),
-  m_operation_thread(nullptr), m_monitor_thread(nullptr), m_pid(LLDB_INVALID_PROCESS_ID), m_terminal_fd(-1), m_operation(0) {
+  m_operation_thread(), m_monitor_thread(), m_pid(LLDB_INVALID_PROCESS_ID), m_terminal_fd(-1), m_operation(0) {
   using namespace std::placeholders;
 
   std::unique_ptr args(
@@ -730,20 +730,22 @@
   }
 
   // Finally, start monitoring the child process for change in state.
-  m_monitor_thread = Host::StartMonitoringChildProcess(
+  llvm::Expected monitor_thread =
+Host::StartMonitoringChildProcess(
   std::bind(&ProcessMonitor::MonitorCallback, this, _1, _2, _3, _4),
   GetPID(), true);
-  if (!m_monitor_thread->IsJoinable()) {
+  if (!monitor_thread || !monitor_thread->IsJoinable()) {
 error.SetErrorToGenericError();
 error.SetErrorString("Process launch failed.");
 return;
   }
+  m_monitor_thread = *monitor_thread;
 }
 
 ProcessMonitor::ProcessMonitor(ProcessFreeBSD *process, lldb::pid_t pid,
lldb_private::Status &error)
 : m_process(static_cast(process)),
-  m_operation_thread(nullptr), m_monitor_thread(nullptr), m_pid(pid), m_terminal_fd(-1), m_operation(0) {
+  m_operation_thread(), m_monitor_thread(), m_pid(pid), m_terminal_fd(-1), m_operation(0) {
   using namespace std::placeholders;
 
   sem_init(&m_operation_pending, 0, 0);
@@ -768,14 +770,16 @@
   }
 
   // Finally, start monitoring the child process for change in state.
-  m_monitor_thread = Host::StartMonitoringChildProcess(
+  llvm::Expected monitor_thread =
+Host::StartMonitoringChildProcess(
   std::bind(&ProcessMonitor::MonitorCallback, this, _1, _2, _3, _4),
   GetPID(), true);
-  if (!m_monitor_thread->IsJoinable()) {
+  if (!monitor_thread || !monitor_thread->IsJoinable()) {
 error.SetErrorToGenericError();
 error.SetErrorString("Process attach failed.");
 return;
   }
+  m_monitor_thread = *monitor_thread;
 }
 
 ProcessMonitor::~ProcessMonitor() { StopMonitor(); }
@@ -784,13 +788,15 @@
 void ProcessMonitor::StartLaunchOpThread(LaunchArgs *args, Status &error) {
   static const char *g_thread_name = "lldb.process.freebsd.operation";
 
-  if (m_operation_thread->IsJoinable())
+  if (m_operation_thread && m_operation_thread->IsJoinable())
 return;
 
-  m_operation_thread =
-  ThreadLauncher::LaunchThread(g_thread_name, LaunchOpThread, args);
-  if (!m_operation_thread)
- error = m_operation_thread.takeError();
+  llvm::Expected operation_thread =
+ThreadLauncher::LaunchThread(g_thread_name, LaunchOpThread, args);
+  if (operation_thread)
+m_operation_thread = *operation_thread;
+  else
+error = operation_thread.takeError();
 }
 
 void *ProcessMonitor::LaunchOpThread(void *arg) {
@@ -952,14 +958,15 @@
  lldb_private::Status &error) {
   static const char *g_thread_name = "lldb.process.freebsd.operation";
 
-  if (m_operation_thread->IsJoinable())
+  if (m_operation_thread && m_operation_thread->IsJoinable())
 return;
 
-  m_operation_thread =
-  ThreadLauncher::LaunchThread(g_thread_name, AttachOpThread, args);
-
-  if (!m_operation_thread)
-	error = m_operation_thread.takeError();
+  llvm::Expected operation_thread =
+ThreadLauncher::LaunchThread(g_thread_name, AttachOpThread, args);
+  if (operation_thread)
+m_operation_thread = *operation_thread;
+  else
+error = operation_thread.takeError();
 }
 
 void *ProcessMonitor::AttachOpThread(void *arg) {
@@ -1374,7 +1381,7 @@
 }
 
 void ProcessMonitor::Sto