From 6ae81f2b1af78843321d48538428a0e188400d9c Mon Sep 17 00:00:00 2001 From: Luca Falavigna Date: Fri, 23 Aug 2013 09:35:00 +0000 Subject: [PATCH 01/14] Re-enable libprofile_rt on Sparc --- debian/changelog | 9 +++++++-- debian/patches/libprofile_rt_sparc.patch | 17 +++++++++++++++++ debian/patches/series | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 debian/patches/libprofile_rt_sparc.patch diff --git a/debian/changelog b/debian/changelog index 53c6a25d..828d1600 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,13 @@ -llvm-toolchain-3.3 (1:3.3-8) unstable; urgency=low +llvm-toolchain-3.3 (1:3.3-8) UNRELEASED; urgency=low + [ Sylvestre Ledru ] * Fix an other issues under HURD... - -- + [ Luca Falavigna ] + * debian/patches/libprofile_rt_sparc.patch: + - Re-enable libprofile_rt on Sparc, fix FTBFS. + + -- Sylvestre Ledru Thu, 22 Aug 2013 14:28:25 +0200 llvm-toolchain-3.3 (1:3.3-7) unstable; urgency=low diff --git a/debian/patches/libprofile_rt_sparc.patch b/debian/patches/libprofile_rt_sparc.patch new file mode 100644 index 00000000..5311b81a --- /dev/null +++ b/debian/patches/libprofile_rt_sparc.patch @@ -0,0 +1,17 @@ +Index: llvm-toolchain-3.2-3.2repack/runtime/Makefile +=================================================================== +--- llvm-toolchain-3.2-3.2repack.orig/runtime/Makefile 2010-04-15 21:51:42.000000000 +0200 ++++ llvm-toolchain-3.2-3.2repack/runtime/Makefile 2013-08-23 11:25:15.964131399 +0200 +@@ -14,12 +14,6 @@ + + PARALLEL_DIRS := libprofile + +-# Disable libprofile: a faulty libtool is generated by autoconf which breaks the +-# build on Sparc +-ifeq ($(ARCH), Sparc) +-PARALLEL_DIRS := $(filter-out libprofile, $(PARALLEL_DIRS)) +-endif +- + ifeq ($(TARGET_OS), $(filter $(TARGET_OS), Cygwin MingW Minix)) + PARALLEL_DIRS := $(filter-out libprofile, $(PARALLEL_DIRS)) + endif diff --git a/debian/patches/series b/debian/patches/series index e43484e3..bcb8ef7d 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -31,3 +31,4 @@ kfreebsd-lldb.diff disable-execinfo-usage.diff unwind-chain-inclusion.diff hurd-pathmax.diff +libprofile_rt_sparc.patch From f1f279891ad5dc9d6c225dd4f3f95520327307d0 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 23 Aug 2013 15:08:34 +0000 Subject: [PATCH 02/14] fix a typo --- debian/changelog | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/debian/changelog b/debian/changelog index 828d1600..525e7fea 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,13 +1,13 @@ -llvm-toolchain-3.3 (1:3.3-8) UNRELEASED; urgency=low +llvm-toolchain-3.3 (1:3.3-8) unstable; urgency=low [ Sylvestre Ledru ] - * Fix an other issues under HURD... + * Fix another issues under HURD... [ Luca Falavigna ] * debian/patches/libprofile_rt_sparc.patch: - Re-enable libprofile_rt on Sparc, fix FTBFS. - -- Sylvestre Ledru Thu, 22 Aug 2013 14:28:25 +0200 + -- Sylvestre Ledru Fri, 23 Aug 2013 15:02:05 +0200 llvm-toolchain-3.3 (1:3.3-7) unstable; urgency=low From 61e7dcc1d6849adbf0693bab7ce9ef4df82c6bd9 Mon Sep 17 00:00:00 2001 From: Luca Falavigna Date: Sun, 25 Aug 2013 11:52:27 +0000 Subject: [PATCH 03/14] Add llvm-3.3-dev to lldb-3.3 Depends field --- debian/changelog | 7 +++++++ debian/control | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 525e7fea..a7996d81 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +llvm-toolchain-3.3 (1:3.3-9) UNRELEASED; urgency=low + + * debian/control: + - Add llvm-3.3-dev to lldb-3.3 Depends field (Closes: #715129). + + -- Luca Falavigna Sun, 25 Aug 2013 13:51:40 +0200 + llvm-toolchain-3.3 (1:3.3-8) unstable; urgency=low [ Sylvestre Ledru ] diff --git a/debian/control b/debian/control index afd01da1..f775325f 100644 --- a/debian/control +++ b/debian/control @@ -418,7 +418,7 @@ Description: Low-Level Virtual Machine (LLVM), examples Package: lldb-3.3 Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, libllvm3.3 (= ${binary:Version}), python +Depends: ${shlibs:Depends}, ${misc:Depends}, libllvm3.3 (= ${binary:Version}), python, llvm-3.3-dev Pre-Depends: ${misc:Pre-Depends} Replaces: lldb-3.2 Breaks: lldb-3.2 From 0094db28a9e543541be73d69d8f40f209de45248 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 26 Aug 2013 12:49:53 +0000 Subject: [PATCH 04/14] Only use -fuse-ld=gold on supported distribution. Simplify the backports. --- debian/changelog | 7 ++++++- debian/rules | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index a7996d81..9df630e1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,9 +1,14 @@ llvm-toolchain-3.3 (1:3.3-9) UNRELEASED; urgency=low + [ Luca Falavigna ] * debian/control: - Add llvm-3.3-dev to lldb-3.3 Depends field (Closes: #715129). - -- Luca Falavigna Sun, 25 Aug 2013 13:51:40 +0200 + [ Sylvestre Ledru ] + * Only use -fuse-ld=gold on supported distribution. Simplify the + backports. + + -- Sylvestre Ledru Mon, 26 Aug 2013 14:48:42 +0200 llvm-toolchain-3.3 (1:3.3-8) unstable; urgency=low diff --git a/debian/rules b/debian/rules index f694201d..7f00d742 100755 --- a/debian/rules +++ b/debian/rules @@ -65,9 +65,13 @@ else endif BINUTILS_GOLD_ARCHS := amd64 armhf i386 powerpc powerpcspe ppc64 sparc sparc64 x32 +BINUTILS_GOLD_UNSUPPORTED_DISTRO = wheezy quantal ifneq (,$(findstring $(DEB_HOST_ARCH),$(BINUTILS_GOLD_ARCHS))) +ifeq (,$(findstring $(distrel),$(BINUTILS_GOLD_UNSUPPORTED_DISTRO))) +# -fused-ld=gold enables the gold linker (but is not supported by all archs / distro) LDFLAGS_EXTRA += -fuse-ld=gold endif +endif ifneq (,$(filter codecoverage,$(DEB_BUILD_OPTIONS))) From 0118a145418eee137ab49c5c7c70f21ac48386e6 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 3 Sep 2013 10:35:41 +0000 Subject: [PATCH 05/14] [ Jon Severinsson ] * Merge from llvm-toolchain-3.2 branch up to 3.2repack-11. --- debian/changelog | 127 ++++++++++++++++++++++++++++++++++++++++- debian/clang-3.3.links | 4 +- debian/control | 2 +- debian/rules | 4 +- 4 files changed, 132 insertions(+), 5 deletions(-) diff --git a/debian/changelog b/debian/changelog index 9df630e1..63990c26 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,9 @@ llvm-toolchain-3.3 (1:3.3-9) UNRELEASED; urgency=low * Only use -fuse-ld=gold on supported distribution. Simplify the backports. + [ Jon Severinsson ] + * Merge from llvm-toolchain-3.2 branch up to 3.2repack-11. + -- Sylvestre Ledru Mon, 26 Aug 2013 14:48:42 +0200 llvm-toolchain-3.3 (1:3.3-8) unstable; urgency=low @@ -129,7 +132,118 @@ llvm-toolchain-3.3 (1:3.3~+rc3-1~exp1) experimental; urgency=low -- Sylvestre Ledru Fri, 19 Apr 2013 09:31:38 +0200 -llvm-toolchain-3.2 (1:3.2repack-1~exp3) experimental; urgency=low +llvm-toolchain-3.2 (1:3.2repack-11) unstable; urgency=low + + * dh_auto_clean removed, just like in the 3.3 + * Use the static library libjsoncpp.a instead of shipping library in polly + Backport of the modification of 3.3 + + [ Adam Conrad ] + * Revive deltas from the previous Ubuntu versions of llvm and clang: + - debian/patches/35-ubuntu-releases.diff: Add UbuntuSaucy to table. + - debian/patches/JITEmitter.patch: Fix a segfault in the exception + table of the JIT code emitter (See Launchpad bug #1160587) + + [ Luca Falavigna ] + * debian/patches/libprofile_rt_sparc.patch: + - Re-enable libprofile_rt on Sparc, fix FTBFS. + + -- Sylvestre Ledru Fri, 23 Aug 2013 11:49:09 +0200 + +llvm-toolchain-3.2 (1:3.2repack-10) unstable; urgency=low + + * Fix the wrong package declaration on libstdc++-4.8-dev (Closes: #713944) + + -- Sylvestre Ledru Mon, 24 Jun 2013 23:00:47 +0200 + +llvm-toolchain-3.2 (1:3.2repack-9) unstable; urgency=low + + * Switch to libstdc++ 4.8 instead of 4.7 for the headers (Closes: #712520) + * Depends against libobjc-4.8-dev and libgcc-4.8-dev + * Disable the usage of binutils-gold under armel. It currently fails with: + "attempt to map 2752512 bytes at offset 2066666 exceeds size of file; + the file may be corrupt" + * Add DEBUGMAKE=1 to get information about compiler-rt compilation + * Fix "libclang-common-dev: missing-depends-line" + + -- Sylvestre Ledru Sat, 22 Jun 2013 07:38:41 +0200 + +llvm-toolchain-3.2 (1:3.2repack-8) unstable; urgency=low + + * Fix the build under ia64. Thanks to Luca Falavigna for the patch + (ia64-fix.diff) + * Disable lldb-3.2: + - the quality is not good enough + - We have lldb-3.3 now in the archive + - Too many backported patches would be necessary for lldb-3.2 to work + - It blocks some important transitions (mesa) + * Add the detection of Ubuntu saucy + + -- Sylvestre Ledru Mon, 03 Jun 2013 11:32:29 +0200 + +llvm-toolchain-3.2 (1:3.2repack-7) unstable; urgency=low + + * For now, enable only lldb for amd64 and i386 (blocks too many things) + (Bis) (Closes: #707866) + * Add a symlink of libLLVM-3.2.so.1 to usr/lib/llvm-3.2/lib/libLLVM-3.2.so + to fix make the llvm-config-3.2 --libdir work (Closes: #708677) + + -- Sylvestre Ledru Mon, 27 May 2013 13:20:30 +0200 + +llvm-toolchain-3.2 (1:3.2repack-6) unstable; urgency=low + + * Create the compiler-rt directory to make the install of compiler-rt works + + -- Sylvestre Ledru Sat, 18 May 2013 18:08:52 +0200 + +llvm-toolchain-3.2 (1:3.2repack-5) unstable; urgency=low + + * For now, enable only lldb for amd64 and i386 (blocks too many things) + + -- Sylvestre Ledru Sat, 18 May 2013 10:24:04 +0200 + +llvm-toolchain-3.2 (1:3.2repack-4) unstable; urgency=low + + * Add several patches which, hopefully, will fix the build under ARM, S390, + S390X, etc (lldb-apple_only.diff, lldb-user-remove.diff & lldb-hurd.diff) + * Include sys/wait.h also under kfreebsd (kfreebsd-thread.diff) + + -- Sylvestre Ledru Wed, 15 May 2013 12:04:24 +0200 + +llvm-toolchain-3.2 (1:3.2repack-3) unstable; urgency=low + + * Before the configure, show which version of CC is being used. + * Add support of kfreebsd and hurd in lldb (kfreebsd-hurd-lldb.diff) + * Force the usage of gcc 4.7 for all archs. Should fix some FTBFS + (Closes: #707866) + * Fix the symlink on clang++.1.gz llvm-clang.1.gz (Closes: #707832) + + [ Jon Severinsson ] + * Re-enable the r600 backend and update it to the mesa-9.1.1 tag. + (Closes: #708009) + + -- Sylvestre Ledru Tue, 14 May 2013 12:10:07 +0200 + +llvm-toolchain-3.2 (1:3.2repack-2) unstable; urgency=low + + * Do not depend on libobjc-4.7-dev & libgcc-4.7-dev. + They are still only in experimental + * Disable the usage of binutils-gold under [powerpc powerpcspe ppc64 sparc + sparc64] to fix FTBFS + + -- Sylvestre Ledru Tue, 07 May 2013 13:15:20 +0200 + +llvm-toolchain-3.2 (1:3.2repack-1) unstable; urgency=low + + * Upload to unstable + * Standards-Version update to 3.9.4 + * clang pure virtual function call crash with binaries built with C++11's + std::thread. Upstream commit 178816 (Closes: #705838) + * Introduce a symbols file for libclang1 (Closes: #705672) + + -- Sylvestre Ledru Sun, 21 Apr 2013 14:06:23 +0200 + +llvm-toolchain-3.2 (1:3.2repack-1~exp4) experimental; urgency=low * Build using binutls-gold to improve the quality of the binaries. See: http://allievi.sssup.it/techblog/?p=791 @@ -138,6 +252,17 @@ llvm-toolchain-3.2 (1:3.2repack-1~exp3) experimental; urgency=low See: 31-powerpcspe.diff * Fix the path detection of scan-build (Closes: #698352) See: 32-scan-build-path.diff + * debian/patches/r600-snapshot.diff: Move backports into individual patches. + * debian/patches/r600-snapshot.diff: Update to mesa-9.1 git tag. + (Closes: #703671, #697356) + * Fix a typo in the detection of the vendor + + [ Peter Michael Green ] + * Use binutils-gold only on architectures where it is actually available + * 33-armhf-defaults.diff Fix defaults to use correct CPU and FPU for + debian armhf (Closes: #704111) + * 34-powerpc-no-altivec.diff disable altivec by default on powerpc because + debian powerpc does not require altivec (patch cherry picked from ubuntu) -- Sylvestre Ledru Thu, 14 Mar 2013 17:47:12 +0100 diff --git a/debian/clang-3.3.links b/debian/clang-3.3.links index 7ef4aa32..d42536f7 100644 --- a/debian/clang-3.3.links +++ b/debian/clang-3.3.links @@ -1,5 +1,5 @@ -usr/share/man/man1/clang.1.gz usr/share/man/man1/llvm-clang.1.gz -usr/share/man/man1/clang.1.gz usr/share/man/man1/clang++.1.gz +usr/share/man/man1/clang-3.3.1.gz usr/share/man/man1/llvm-clang.1.gz +usr/share/man/man1/clang-3.3.1.gz usr/share/man/man1/clang++.1.gz /usr/share/clang/scan-build/scan-build /usr/bin/scan-build /usr/share/clang/scan-view/scan-view /usr/bin/scan-view /usr/bin/clang /usr/bin/llvm-clang diff --git a/debian/control b/debian/control index f775325f..f52bb7a3 100644 --- a/debian/control +++ b/debian/control @@ -209,7 +209,7 @@ Description: clang library - Development package Package: libclang-common-3.3-dev Architecture: any Section: libdevel -Depends: ${misc:Depends}, libllvm3.3 (= ${binary:Version}) +Depends: ${shlibs:Depends}, ${misc:Depends}, libllvm3.3 (= ${binary:Version}) Replaces: llvm-3.3-dev (<< 1:3.2repack), libclang-3.3-dev Breaks: llvm-3.3-dev (<< 1:3.2repack) Description: clang library - Common development package diff --git a/debian/rules b/debian/rules index 7f00d742..8726371d 100755 --- a/debian/rules +++ b/debian/rules @@ -94,6 +94,8 @@ debian/%: debian/%.in sed -e 's|@DEB_HOST_MULTIARCH@|$(DEB_HOST_MULTIARCH)|g' -e "s|@OCAML_STDLIB_DIR@|$(OCAML_STDLIB_DIR)|g" -e "s|@LLVM_VERSION@|$(LLVM_VERSION)|g" $< > $@ override_dh_auto_configure: debian/lldb-$(LLVM_VERSION).install debian/lldb-$(LLVM_VERSION).links debian/libllvm$(LLVM_VERSION).install debian/llvm-$(LLVM_VERSION)-dev.links debian/libllvm-$(LLVM_VERSION)-ocaml-dev.install debian/libllvm-$(LLVM_VERSION)-ocaml-dev.dirs debian/llvm-$(LLVM_VERSION)-runtime.binfmt debian/llvm-$(LLVM_VERSION)-runtime.prerm debian/pollycc + echo "Using gcc: " + $(CC) -v mkdir -p $(TARGET_BUILD) mkdir -p clang/include/clang/Debian sed -e "s|@DEB_HOST_MULTIARCH@|$(DEB_HOST_MULTIARCH)|" \ @@ -150,7 +152,7 @@ override_dh_auto_configure: debian/lldb-$(LLVM_VERSION).install debian/lldb-$(LL override_dh_auto_build: - $(MAKE) $(NJOBS) -C $(TARGET_BUILD) VERBOSE=1 CLANG_VENDOR=$(VENDOR) CXXFLAGS="$(CXXFLAGS_EXTRA) -std=c++0x" LDFLAGS="$(LDFLAGS_EXTRA)" REQUIRES_RTTI=1 + $(MAKE) $(NJOBS) -C $(TARGET_BUILD) VERBOSE=1 CLANG_VENDOR=$(VENDOR) CXXFLAGS="$(CXXFLAGS_EXTRA) -std=c++0x" LDFLAGS="$(LDFLAGS_EXTRA)" REQUIRES_RTTI=1 DEBUGMAKE=1 override_dh_prep: build_doc dh_prep From 1d19b1c9c7c678017833c98ead4941ac20372384 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 3 Sep 2013 10:36:27 +0000 Subject: [PATCH 06/14] Jon Severinsson: Drop auto-generated file debian/libllvm3.3.install --- debian/changelog | 1 + debian/libllvm3.3.install | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 debian/libllvm3.3.install diff --git a/debian/changelog b/debian/changelog index 63990c26..a8760f2e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,6 +10,7 @@ llvm-toolchain-3.3 (1:3.3-9) UNRELEASED; urgency=low [ Jon Severinsson ] * Merge from llvm-toolchain-3.2 branch up to 3.2repack-11. + * Drop auto-generated file debian/libllvm3.3.install. -- Sylvestre Ledru Mon, 26 Aug 2013 14:48:42 +0200 diff --git a/debian/libllvm3.3.install b/debian/libllvm3.3.install deleted file mode 100644 index 416052f0..00000000 --- a/debian/libllvm3.3.install +++ /dev/null @@ -1 +0,0 @@ -usr/lib/llvm-3.3/lib/libLLVM-3.3.so.1 /usr/lib/x86_64-linux-gnu/ From 4ac4be96686aaabd32d2441911a4d47595b48cb5 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 3 Sep 2013 10:39:03 +0000 Subject: [PATCH 07/14] Jon Severinsson: * Automatically determine GCC_VERSION and dep:devlibs based on g++ package version. --- debian/changelog | 1 + debian/rules | 27 +++++++++------------------ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/debian/changelog b/debian/changelog index a8760f2e..517299c1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,7 @@ llvm-toolchain-3.3 (1:3.3-9) UNRELEASED; urgency=low [ Jon Severinsson ] * Merge from llvm-toolchain-3.2 branch up to 3.2repack-11. * Drop auto-generated file debian/libllvm3.3.install. + * Automatically determine GCC_VERSION and dep:devlibs based on g++ package version. -- Sylvestre Ledru Mon, 26 Aug 2013 14:48:42 +0200 diff --git a/debian/rules b/debian/rules index 8726371d..8eb1a153 100755 --- a/debian/rules +++ b/debian/rules @@ -1,7 +1,7 @@ #!/usr/bin/make -f TARGET_BUILD := build-llvm -GCC_VERSION := 4.7 +GCC_VERSION := $(shell dpkg-query -W -f '$${Version}' g++ | sed -rne 's,^([0-9]+:)?([0-9]+\.[0-9]+).*$$,\2,p') LLVM_VERSION := 3.3 SONAME_EXT := 1 DEBIAN_REVISION := $(shell dpkg-parsechangelog | sed -rne 's,^Version: .*-(.*),\1,p') @@ -24,6 +24,9 @@ ifeq ($(distrel),n/a) distrel := sid endif +export CC=gcc-$(GCC_VERSION) +export CXX=g++-$(GCC_VERSION) + LDFLAGS_EXTRA= CXXFLAGS_EXTRA= @@ -44,24 +47,12 @@ ifneq (,$(findstring $(DEB_HOST_ARCH),armel)) opt_flags += -marm endif -ifeq ($(distribution),Ubuntu) - ifeq ($(distrel),precise) - control_vars = '-Vdep:devlibs=libstdc++6-4.6-dev' - endif - ifeq ($(distrel),quantal) - control_vars = '-Vdep:devlibs=libstdc++6-4.7-dev' - endif - ifeq ($(distrel),raring) - control_vars = '-Vdep:devlibs=libstdc++6-4.7-dev, libgcc-4.7-dev, libobjc-4.7-dev' - endif - +ifeq ($(shell dpkg --compare-versions $(shell dpkg-query -W -f '$${Version}' g++-$(GCC_VERSION)) ge 4.8-20121128-1~ ; echo $$?),0) + control_vars = '-Vdep:devlibs=libstdc++-$(GCC_VERSION)-dev, libgcc-$(GCC_VERSION)-dev, libobjc-$(GCC_VERSION)-dev' +else ifeq ($(shell dpkg --compare-versions $(shell dpkg-query -W -f '$${Version}' g++-$(GCC_VERSION)) ge 4.7.2-10~ ; echo $$?),0) + control_vars = '-Vdep:devlibs=libstdc++6-$(GCC_VERSION)-dev, libgcc-$(GCC_VERSION)-dev, libobjc-$(GCC_VERSION)-dev' else - ifeq ($(distrel),wheezy) - control_vars = '-Vdep:devlibs=libstdc++6-4.7-dev' - else - # Debian experimental - control_vars = '-Vdep:devlibs=libstdc++6-4.7-dev, libgcc-4.7-dev, libobjc-4.7-dev' - endif + control_vars = '-Vdep:devlibs=libstdc++6-$(GCC_VERSION)-dev' endif BINUTILS_GOLD_ARCHS := amd64 armhf i386 powerpc powerpcspe ppc64 sparc sparc64 x32 From 128450efafa460d0011fca4887c7db3b18509716 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 3 Sep 2013 10:40:38 +0000 Subject: [PATCH 08/14] Jon Severinsson: Automatically determine if -fuse-ld=gold is supported based on binutils package version --- debian/changelog | 1 + debian/control | 4 ++-- debian/rules | 9 +-------- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/debian/changelog b/debian/changelog index 517299c1..713f17af 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,6 +12,7 @@ llvm-toolchain-3.3 (1:3.3-9) UNRELEASED; urgency=low * Merge from llvm-toolchain-3.2 branch up to 3.2repack-11. * Drop auto-generated file debian/libllvm3.3.install. * Automatically determine GCC_VERSION and dep:devlibs based on g++ package version. + * Automatically determine if -fuse-ld=gold is supported based on binutils package version. -- Sylvestre Ledru Mon, 26 Aug 2013 14:48:42 +0200 diff --git a/debian/control b/debian/control index f52bb7a3..4e9a4f4e 100644 --- a/debian/control +++ b/debian/control @@ -8,8 +8,8 @@ Build-Depends: debhelper (>= 9.0), flex, bison, dejagnu, tcl8.5, expect, sharutils, autotools-dev (>= 20060702.1), libffi-dev (>= 3.0.9), lsb-release, patchutils, diffstat, xz-utils, chrpath, python-dev, libedit-dev, swig, python-sphinx, ocaml-nox, binutils-dev, libcloog-isl-dev, - libisl-dev (>= 0.11.1), binutils (>= 2.23.52.20130522), - lcov, procps, help2man, libjsoncpp-dev + libisl-dev (>= 0.11.1), libjsoncpp-dev, + lcov, procps, help2man Build-Conflicts: oprofile, ocaml Standards-Version: 3.9.4 Homepage: http://www.llvm.org/ diff --git a/debian/rules b/debian/rules index 8eb1a153..705752fe 100755 --- a/debian/rules +++ b/debian/rules @@ -18,12 +18,6 @@ DEB_HOST_ARCH = $(shell dpkg-architecture -qDEB_HOST_ARCH) OCAML_STDLIB_DIR ?= $(shell ocamlc -where) -distribution := $(shell lsb_release --id --short) -distrel := $(shell lsb_release --codename --short) -ifeq ($(distrel),n/a) - distrel := sid -endif - export CC=gcc-$(GCC_VERSION) export CXX=g++-$(GCC_VERSION) @@ -56,9 +50,8 @@ else endif BINUTILS_GOLD_ARCHS := amd64 armhf i386 powerpc powerpcspe ppc64 sparc sparc64 x32 -BINUTILS_GOLD_UNSUPPORTED_DISTRO = wheezy quantal +ifeq ($(shell dpkg --compare-versions $(shell dpkg-query -W -f '$${Version}' binutils) ge 2.23.1-1~exp3 ; echo $$?),0) ifneq (,$(findstring $(DEB_HOST_ARCH),$(BINUTILS_GOLD_ARCHS))) -ifeq (,$(findstring $(distrel),$(BINUTILS_GOLD_UNSUPPORTED_DISTRO))) # -fused-ld=gold enables the gold linker (but is not supported by all archs / distro) LDFLAGS_EXTRA += -fuse-ld=gold endif From 61e58e71fdbbbb61f517bedc6c3955427334fa60 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 3 Sep 2013 15:31:30 +0000 Subject: [PATCH 09/14] * Add more fixes for the HURD port... * Automatically determine GCC_VERSION and dep:devlibs based on g++ package version. * Automatically determine if -fuse-ld=gold is supported based on binutils package version. * debian/patches/lldb-link-atomic.diff: Link lldb with -latomic to get builtin GCC atomic helpers on arches (like powerpc) that need them. --- debian/changelog | 11 +++++++++-- debian/patches/hurd-pathmax.diff | 20 ++++++++++++++++++-- debian/patches/lldb-hurd.diff | 28 ++++++++++++++++++++++++++++ debian/patches/lldb-link-atomic.diff | 16 ++++++++++++++++ debian/patches/series | 2 ++ 5 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 debian/patches/lldb-hurd.diff create mode 100644 debian/patches/lldb-link-atomic.diff diff --git a/debian/changelog b/debian/changelog index 713f17af..9d7ad07e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,12 +7,19 @@ llvm-toolchain-3.3 (1:3.3-9) UNRELEASED; urgency=low [ Sylvestre Ledru ] * Only use -fuse-ld=gold on supported distribution. Simplify the backports. + * Add more fixes for the HURD port... [ Jon Severinsson ] * Merge from llvm-toolchain-3.2 branch up to 3.2repack-11. * Drop auto-generated file debian/libllvm3.3.install. - * Automatically determine GCC_VERSION and dep:devlibs based on g++ package version. - * Automatically determine if -fuse-ld=gold is supported based on binutils package version. + * Automatically determine GCC_VERSION and dep:devlibs based on g++ package + version. + * Automatically determine if -fuse-ld=gold is supported based on binutils + package version. + + [ Adam Conrad ] + * debian/patches/lldb-link-atomic.diff: Link lldb with -latomic to get + builtin GCC atomic helpers on arches (like powerpc) that need them. -- Sylvestre Ledru Mon, 26 Aug 2013 14:48:42 +0200 diff --git a/debian/patches/hurd-pathmax.diff b/debian/patches/hurd-pathmax.diff index 227d7759..0abe1eed 100644 --- a/debian/patches/hurd-pathmax.diff +++ b/debian/patches/hurd-pathmax.diff @@ -1,7 +1,7 @@ Index: llvm-toolchain-3.3-3.3/clang/lib/Basic/FileManager.cpp =================================================================== ---- llvm-toolchain-3.3-3.3.orig/clang/lib/Basic/FileManager.cpp 2013-01-26 17:29:36.000000000 +0100 -+++ llvm-toolchain-3.3-3.3/clang/lib/Basic/FileManager.cpp 2013-08-23 09:53:21.538337851 +0200 +--- llvm-toolchain-3.3-3.3.orig/clang/lib/Basic/FileManager.cpp 2013-01-26 16:29:36.000000000 +0000 ++++ llvm-toolchain-3.3-3.3/clang/lib/Basic/FileManager.cpp 2013-08-28 10:29:30.000000000 +0000 @@ -43,6 +43,11 @@ #if defined(LLVM_ON_UNIX) #include @@ -14,3 +14,19 @@ Index: llvm-toolchain-3.3-3.3/clang/lib/Basic/FileManager.cpp using namespace clang; // FIXME: Enhance libsystem to support inode and other fields. +Index: llvm-toolchain-3.3-3.3/lldb/include/lldb/lldb-defines.h +=================================================================== +--- llvm-toolchain-3.3-3.3.orig/lldb/include/lldb/lldb-defines.h 2013-08-28 14:14:04.000000000 +0000 ++++ llvm-toolchain-3.3-3.3/lldb/include/lldb/lldb-defines.h 2013-08-28 14:15:01.000000000 +0000 +@@ -12,6 +12,11 @@ + + #include "lldb/lldb-types.h" + ++// For GNU Hurd ++#if defined(__GNU__) && !defined(PATH_MAX) ++# define PATH_MAX 4096 ++#endif ++ + #if !defined(UINT32_MAX) + #define UINT32_MAX 4294967295U + #endif diff --git a/debian/patches/lldb-hurd.diff b/debian/patches/lldb-hurd.diff new file mode 100644 index 00000000..e5d2d262 --- /dev/null +++ b/debian/patches/lldb-hurd.diff @@ -0,0 +1,28 @@ +Index: llvm-toolchain-3.3-3.3/lldb/include/lldb/Host/Config.h +=================================================================== +--- llvm-toolchain-3.3-3.3.orig/lldb/include/lldb/Host/Config.h 2013-08-28 10:29:30.000000000 +0000 ++++ llvm-toolchain-3.3-3.3/lldb/include/lldb/Host/Config.h 2013-08-28 17:23:00.000000000 +0000 +@@ -14,7 +14,7 @@ + + #include "lldb/Host/macosx/Config.h" + +-#elif defined(__linux__) ++#elif defined(__linux__) || defined(__GNU__) + + #include "lldb/Host/linux/Config.h" + +Index: llvm-toolchain-3.3-3.3/lldb/source/Host/common/Host.cpp +=================================================================== +--- llvm-toolchain-3.3-3.3.orig/lldb/source/Host/common/Host.cpp 2013-08-28 10:29:30.000000000 +0000 ++++ llvm-toolchain-3.3-3.3/lldb/source/Host/common/Host.cpp 2013-08-28 17:25:38.000000000 +0000 +@@ -16,8 +16,10 @@ + #include + #include + #include ++#ifndef __GNU__ + #include + #include ++#endif + #include + + #if defined (__APPLE__) diff --git a/debian/patches/lldb-link-atomic.diff b/debian/patches/lldb-link-atomic.diff new file mode 100644 index 00000000..3bfe368b --- /dev/null +++ b/debian/patches/lldb-link-atomic.diff @@ -0,0 +1,16 @@ +Description: Link lldb with -latomic to get GCC atomic helpers +Author: Adam Conrad +Forwarded: no +Last-Update: 2013-08-21 + +--- llvm-toolchain-3.3-3.3.orig/lldb/lib/Makefile ++++ llvm-toolchain-3.3-3.3/lldb/lib/Makefile +@@ -140,6 +140,8 @@ ifeq ($(HOST_OS), $(filter $(HOST_OS), L + LLVMLibsOptions += -Wl,--no-undefined + # Link in python + LLVMLibsOptions += $(PYTHON_BUILD_FLAGS) -lrt ++ # Link GCC atomic helper library ++ LLVMLibsOptions += -latomic + LLVMLibsOptions += -Wl,--soname,lib$(LIBRARYNAME)$(SHLIBEXT) + endif + diff --git a/debian/patches/series b/debian/patches/series index bcb8ef7d..0bd98168 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -32,3 +32,5 @@ disable-execinfo-usage.diff unwind-chain-inclusion.diff hurd-pathmax.diff libprofile_rt_sparc.patch +lldb-hurd.diff +lldb-link-atomic.diff From 90832a32391944fd7bb343489a10e7e4ddf329f9 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 4 Sep 2013 14:18:11 +0000 Subject: [PATCH 10/14] Update of the patches for hurd --- debian/patches/hurd-pathmax.diff | 3865 ++++++++++++++++++++++++++++++ debian/patches/lldb-hurd.diff | 1520 ++++++++++++ 2 files changed, 5385 insertions(+) diff --git a/debian/patches/hurd-pathmax.diff b/debian/patches/hurd-pathmax.diff index 0abe1eed..c6490467 100644 --- a/debian/patches/hurd-pathmax.diff +++ b/debian/patches/hurd-pathmax.diff @@ -30,3 +30,3868 @@ Index: llvm-toolchain-3.3-3.3/lldb/include/lldb/lldb-defines.h #if !defined(UINT32_MAX) #define UINT32_MAX 4294967295U #endif +Index: llvm-toolchain-3.3-3.3/home/sylvestre/llvm-toolchain-3.3-3.3/tools/lldb/include/lldb/Target/Process.h +=================================================================== +--- llvm-toolchain-3.3-3.3.orig/home/sylvestre/llvm-toolchain-3.3-3.3/tools/lldb/include/lldb/Target/Process.h 2013-08-28 10:29:30.000000000 +0000 ++++ /dev/null 1970-01-01 00:00:00.000000000 +0000 +@@ -1,3860 +0,0 @@ +-//===-- Process.h -----------------------------------------------*- C++ -*-===// +-// +-// The LLVM Compiler Infrastructure +-// +-// This file is distributed under the University of Illinois Open Source +-// License. See LICENSE.TXT for details. +-// +-//===----------------------------------------------------------------------===// +- +-#ifndef liblldb_Process_h_ +-#define liblldb_Process_h_ +- +-// C Includes +-#include +-#include +- +-// C++ Includes +-#include +-#include +-#include +- +-// Other libraries and framework includes +-// Project includes +-#include "lldb/lldb-private.h" +-#include "lldb/Core/ArchSpec.h" +-#include "lldb/Core/Broadcaster.h" +-#include "lldb/Core/Communication.h" +-#include "lldb/Core/Error.h" +-#include "lldb/Core/Event.h" +-#include "lldb/Core/RangeMap.h" +-#include "lldb/Core/StringList.h" +-#include "lldb/Core/ThreadSafeValue.h" +-#include "lldb/Core/PluginInterface.h" +-#include "lldb/Core/UserSettingsController.h" +-#include "lldb/Breakpoint/BreakpointSiteList.h" +-#include "lldb/Expression/ClangPersistentVariables.h" +-#include "lldb/Expression/IRDynamicChecks.h" +-#include "lldb/Host/FileSpec.h" +-#include "lldb/Host/Host.h" +-#include "lldb/Host/ReadWriteLock.h" +-#include "lldb/Interpreter/Args.h" +-#include "lldb/Interpreter/Options.h" +-#include "lldb/Target/ExecutionContextScope.h" +-#include "lldb/Target/Memory.h" +-#include "lldb/Target/ThreadList.h" +-#include "lldb/Target/UnixSignals.h" +-#include "lldb/Utility/PseudoTerminal.h" +- +-namespace lldb_private { +- +-//---------------------------------------------------------------------- +-// ProcessProperties +-//---------------------------------------------------------------------- +-class ProcessProperties : public Properties +-{ +-public: +- ProcessProperties(bool is_global); +- +- virtual +- ~ProcessProperties(); +- +- bool +- GetDisableMemoryCache() const; +- +- Args +- GetExtraStartupCommands () const; +- +- void +- SetExtraStartupCommands (const Args &args); +- +- FileSpec +- GetPythonOSPluginPath () const; +- +- void +- SetPythonOSPluginPath (const FileSpec &file); +- +- bool +- GetIgnoreBreakpointsInExpressions () const; +- +- void +- SetIgnoreBreakpointsInExpressions (bool ignore); +- +- bool +- GetUnwindOnErrorInExpressions () const; +- +- void +- SetUnwindOnErrorInExpressions (bool ignore); +- +- bool +- GetStopOnSharedLibraryEvents () const; +- +- void +- SetStopOnSharedLibraryEvents (bool stop); +- +- bool +- GetDetachKeepsStopped () const; +- +- void +- SetDetachKeepsStopped (bool keep_stopped); +-}; +- +-typedef std::shared_ptr ProcessPropertiesSP; +- +-//---------------------------------------------------------------------- +-// ProcessInfo +-// +-// A base class for information for a process. This can be used to fill +-// out information for a process prior to launching it, or it can be +-// used for an instance of a process and can be filled in with the +-// existing values for that process. +-//---------------------------------------------------------------------- +-class ProcessInfo +-{ +-public: +- ProcessInfo () : +- m_executable (), +- m_arguments (), +- m_environment (), +- m_uid (UINT32_MAX), +- m_gid (UINT32_MAX), +- m_arch(), +- m_pid (LLDB_INVALID_PROCESS_ID) +- { +- } +- +- ProcessInfo (const char *name, +- const ArchSpec &arch, +- lldb::pid_t pid) : +- m_executable (name, false), +- m_arguments (), +- m_environment(), +- m_uid (UINT32_MAX), +- m_gid (UINT32_MAX), +- m_arch (arch), +- m_pid (pid) +- { +- } +- +- void +- Clear () +- { +- m_executable.Clear(); +- m_arguments.Clear(); +- m_environment.Clear(); +- m_uid = UINT32_MAX; +- m_gid = UINT32_MAX; +- m_arch.Clear(); +- m_pid = LLDB_INVALID_PROCESS_ID; +- } +- +- const char * +- GetName() const +- { +- return m_executable.GetFilename().GetCString(); +- } +- +- size_t +- GetNameLength() const +- { +- return m_executable.GetFilename().GetLength(); +- } +- +- FileSpec & +- GetExecutableFile () +- { +- return m_executable; +- } +- +- void +- SetExecutableFile (const FileSpec &exe_file, bool add_exe_file_as_first_arg) +- { +- if (exe_file) +- { +- m_executable = exe_file; +- if (add_exe_file_as_first_arg) +- { +- char filename[PATH_MAX]; +- if (exe_file.GetPath(filename, sizeof(filename))) +- m_arguments.InsertArgumentAtIndex (0, filename); +- } +- } +- else +- { +- m_executable.Clear(); +- } +- } +- +- const FileSpec & +- GetExecutableFile () const +- { +- return m_executable; +- } +- +- uint32_t +- GetUserID() const +- { +- return m_uid; +- } +- +- uint32_t +- GetGroupID() const +- { +- return m_gid; +- } +- +- bool +- UserIDIsValid () const +- { +- return m_uid != UINT32_MAX; +- } +- +- bool +- GroupIDIsValid () const +- { +- return m_gid != UINT32_MAX; +- } +- +- void +- SetUserID (uint32_t uid) +- { +- m_uid = uid; +- } +- +- void +- SetGroupID (uint32_t gid) +- { +- m_gid = gid; +- } +- +- ArchSpec & +- GetArchitecture () +- { +- return m_arch; +- } +- +- const ArchSpec & +- GetArchitecture () const +- { +- return m_arch; +- } +- +- lldb::pid_t +- GetProcessID () const +- { +- return m_pid; +- } +- +- void +- SetProcessID (lldb::pid_t pid) +- { +- m_pid = pid; +- } +- +- bool +- ProcessIDIsValid() const +- { +- return m_pid != LLDB_INVALID_PROCESS_ID; +- } +- +- void +- Dump (Stream &s, Platform *platform) const; +- +- Args & +- GetArguments () +- { +- return m_arguments; +- } +- +- const Args & +- GetArguments () const +- { +- return m_arguments; +- } +- +- const char * +- GetArg0 () const +- { +- if (m_arg0.empty()) +- return NULL; +- return m_arg0.c_str(); +- } +- +- void +- SetArg0 (const char *arg) +- { +- if (arg && arg[0]) +- m_arg0 = arg; +- else +- m_arg0.clear(); +- } +- +- void +- SetArguments (const Args& args, bool first_arg_is_executable); +- +- void +- SetArguments (char const **argv, bool first_arg_is_executable); +- +- Args & +- GetEnvironmentEntries () +- { +- return m_environment; +- } +- +- const Args & +- GetEnvironmentEntries () const +- { +- return m_environment; +- } +- +-protected: +- FileSpec m_executable; +- std::string m_arg0; // argv[0] if supported. If empty, then use m_executable. +- // Not all process plug-ins support specifying an argv[0] +- // that differs from the resolved platform executable +- // (which is in m_executable) +- Args m_arguments; // All program arguments except argv[0] +- Args m_environment; +- uint32_t m_uid; +- uint32_t m_gid; +- ArchSpec m_arch; +- lldb::pid_t m_pid; +-}; +- +-//---------------------------------------------------------------------- +-// ProcessInstanceInfo +-// +-// Describes an existing process and any discoverable information that +-// pertains to that process. +-//---------------------------------------------------------------------- +-class ProcessInstanceInfo : public ProcessInfo +-{ +-public: +- ProcessInstanceInfo () : +- ProcessInfo (), +- m_euid (UINT32_MAX), +- m_egid (UINT32_MAX), +- m_parent_pid (LLDB_INVALID_PROCESS_ID) +- { +- } +- +- ProcessInstanceInfo (const char *name, +- const ArchSpec &arch, +- lldb::pid_t pid) : +- ProcessInfo (name, arch, pid), +- m_euid (UINT32_MAX), +- m_egid (UINT32_MAX), +- m_parent_pid (LLDB_INVALID_PROCESS_ID) +- { +- } +- +- void +- Clear () +- { +- ProcessInfo::Clear(); +- m_euid = UINT32_MAX; +- m_egid = UINT32_MAX; +- m_parent_pid = LLDB_INVALID_PROCESS_ID; +- } +- +- uint32_t +- GetEffectiveUserID() const +- { +- return m_euid; +- } +- +- uint32_t +- GetEffectiveGroupID() const +- { +- return m_egid; +- } +- +- bool +- EffectiveUserIDIsValid () const +- { +- return m_euid != UINT32_MAX; +- } +- +- bool +- EffectiveGroupIDIsValid () const +- { +- return m_egid != UINT32_MAX; +- } +- +- void +- SetEffectiveUserID (uint32_t uid) +- { +- m_euid = uid; +- } +- +- void +- SetEffectiveGroupID (uint32_t gid) +- { +- m_egid = gid; +- } +- +- lldb::pid_t +- GetParentProcessID () const +- { +- return m_parent_pid; +- } +- +- void +- SetParentProcessID (lldb::pid_t pid) +- { +- m_parent_pid = pid; +- } +- +- bool +- ParentProcessIDIsValid() const +- { +- return m_parent_pid != LLDB_INVALID_PROCESS_ID; +- } +- +- void +- Dump (Stream &s, Platform *platform) const; +- +- static void +- DumpTableHeader (Stream &s, Platform *platform, bool show_args, bool verbose); +- +- void +- DumpAsTableRow (Stream &s, Platform *platform, bool show_args, bool verbose) const; +- +-protected: +- uint32_t m_euid; +- uint32_t m_egid; +- lldb::pid_t m_parent_pid; +-}; +- +- +-//---------------------------------------------------------------------- +-// ProcessLaunchInfo +-// +-// Describes any information that is required to launch a process. +-//---------------------------------------------------------------------- +- +-class ProcessLaunchInfo : public ProcessInfo +-{ +-public: +- +- class FileAction +- { +- public: +- enum Action +- { +- eFileActionNone, +- eFileActionClose, +- eFileActionDuplicate, +- eFileActionOpen +- }; +- +- +- FileAction () : +- m_action (eFileActionNone), +- m_fd (-1), +- m_arg (-1), +- m_path () +- { +- } +- +- void +- Clear() +- { +- m_action = eFileActionNone; +- m_fd = -1; +- m_arg = -1; +- m_path.clear(); +- } +- +- bool +- Close (int fd); +- +- bool +- Duplicate (int fd, int dup_fd); +- +- bool +- Open (int fd, const char *path, bool read, bool write); +- +- static bool +- AddPosixSpawnFileAction (posix_spawn_file_actions_t *file_actions, +- const FileAction *info, +- Log *log, +- Error& error); +- +- int +- GetFD () const +- { +- return m_fd; +- } +- +- Action +- GetAction () const +- { +- return m_action; +- } +- +- int +- GetActionArgument () const +- { +- return m_arg; +- } +- +- const char * +- GetPath () const +- { +- if (m_path.empty()) +- return NULL; +- return m_path.c_str(); +- } +- +- protected: +- Action m_action; // The action for this file +- int m_fd; // An existing file descriptor +- int m_arg; // oflag for eFileActionOpen*, dup_fd for eFileActionDuplicate +- std::string m_path; // A file path to use for opening after fork or posix_spawn +- }; +- +- ProcessLaunchInfo () : +- ProcessInfo(), +- m_working_dir (), +- m_plugin_name (), +- m_shell (), +- m_flags (0), +- m_file_actions (), +- m_pty (), +- m_resume_count (0), +- m_monitor_callback (NULL), +- m_monitor_callback_baton (NULL), +- m_monitor_signals (false) +- { +- } +- +- ProcessLaunchInfo (const char *stdin_path, +- const char *stdout_path, +- const char *stderr_path, +- const char *working_directory, +- uint32_t launch_flags) : +- ProcessInfo(), +- m_working_dir (), +- m_plugin_name (), +- m_shell (), +- m_flags (launch_flags), +- m_file_actions (), +- m_pty (), +- m_resume_count (0), +- m_monitor_callback (NULL), +- m_monitor_callback_baton (NULL), +- m_monitor_signals (false) +- { +- if (stdin_path) +- { +- ProcessLaunchInfo::FileAction file_action; +- const bool read = true; +- const bool write = false; +- if (file_action.Open(STDIN_FILENO, stdin_path, read, write)) +- AppendFileAction (file_action); +- } +- if (stdout_path) +- { +- ProcessLaunchInfo::FileAction file_action; +- const bool read = false; +- const bool write = true; +- if (file_action.Open(STDOUT_FILENO, stdout_path, read, write)) +- AppendFileAction (file_action); +- } +- if (stderr_path) +- { +- ProcessLaunchInfo::FileAction file_action; +- const bool read = false; +- const bool write = true; +- if (file_action.Open(STDERR_FILENO, stderr_path, read, write)) +- AppendFileAction (file_action); +- } +- if (working_directory) +- SetWorkingDirectory(working_directory); +- } +- +- void +- AppendFileAction (const FileAction &info) +- { +- m_file_actions.push_back(info); +- } +- +- bool +- AppendCloseFileAction (int fd) +- { +- FileAction file_action; +- if (file_action.Close (fd)) +- { +- AppendFileAction (file_action); +- return true; +- } +- return false; +- } +- +- bool +- AppendDuplicateFileAction (int fd, int dup_fd) +- { +- FileAction file_action; +- if (file_action.Duplicate (fd, dup_fd)) +- { +- AppendFileAction (file_action); +- return true; +- } +- return false; +- } +- +- bool +- AppendOpenFileAction (int fd, const char *path, bool read, bool write) +- { +- FileAction file_action; +- if (file_action.Open (fd, path, read, write)) +- { +- AppendFileAction (file_action); +- return true; +- } +- return false; +- } +- +- bool +- AppendSuppressFileAction (int fd, bool read, bool write) +- { +- FileAction file_action; +- if (file_action.Open (fd, "/dev/null", read, write)) +- { +- AppendFileAction (file_action); +- return true; +- } +- return false; +- } +- +- void +- FinalizeFileActions (Target *target, +- bool default_to_use_pty); +- +- size_t +- GetNumFileActions () const +- { +- return m_file_actions.size(); +- } +- +- const FileAction * +- GetFileActionAtIndex (size_t idx) const +- { +- if (idx < m_file_actions.size()) +- return &m_file_actions[idx]; +- return NULL; +- } +- +- const FileAction * +- GetFileActionForFD (int fd) const +- { +- for (size_t idx=0, count=m_file_actions.size(); idx < count; ++idx) +- { +- if (m_file_actions[idx].GetFD () == fd) +- return &m_file_actions[idx]; +- } +- return NULL; +- } +- +- Flags & +- GetFlags () +- { +- return m_flags; +- } +- +- const Flags & +- GetFlags () const +- { +- return m_flags; +- } +- +- const char * +- GetWorkingDirectory () const +- { +- if (m_working_dir.empty()) +- return NULL; +- return m_working_dir.c_str(); +- } +- +- void +- SetWorkingDirectory (const char *working_dir) +- { +- if (working_dir && working_dir[0]) +- m_working_dir.assign (working_dir); +- else +- m_working_dir.clear(); +- } +- +- void +- SwapWorkingDirectory (std::string &working_dir) +- { +- m_working_dir.swap (working_dir); +- } +- +- +- const char * +- GetProcessPluginName () const +- { +- if (m_plugin_name.empty()) +- return NULL; +- return m_plugin_name.c_str(); +- } +- +- void +- SetProcessPluginName (const char *plugin) +- { +- if (plugin && plugin[0]) +- m_plugin_name.assign (plugin); +- else +- m_plugin_name.clear(); +- } +- +- const char * +- GetShell () const +- { +- if (m_shell.empty()) +- return NULL; +- return m_shell.c_str(); +- } +- +- void +- SetShell (const char * path) +- { +- if (path && path[0]) +- { +- m_shell.assign (path); +- m_flags.Set (lldb::eLaunchFlagLaunchInShell); +- } +- else +- { +- m_shell.clear(); +- m_flags.Clear (lldb::eLaunchFlagLaunchInShell); +- } +- } +- +- uint32_t +- GetResumeCount () const +- { +- return m_resume_count; +- } +- +- void +- SetResumeCount (uint32_t c) +- { +- m_resume_count = c; +- } +- +- bool +- GetLaunchInSeparateProcessGroup () +- { +- return m_flags.Test(lldb::eLaunchFlagLaunchInSeparateProcessGroup); +- } +- +- void +- SetLaunchInSeparateProcessGroup (bool separate) +- { +- if (separate) +- m_flags.Set(lldb::eLaunchFlagLaunchInSeparateProcessGroup); +- else +- m_flags.Clear (lldb::eLaunchFlagLaunchInSeparateProcessGroup); +- +- } +- +- void +- Clear () +- { +- ProcessInfo::Clear(); +- m_working_dir.clear(); +- m_plugin_name.clear(); +- m_shell.clear(); +- m_flags.Clear(); +- m_file_actions.clear(); +- m_resume_count = 0; +- } +- +- bool +- ConvertArgumentsForLaunchingInShell (Error &error, +- bool localhost, +- bool will_debug, +- bool first_arg_is_full_shell_command); +- +- void +- SetMonitorProcessCallback (Host::MonitorChildProcessCallback callback, +- void *baton, +- bool monitor_signals) +- { +- m_monitor_callback = callback; +- m_monitor_callback_baton = baton; +- m_monitor_signals = monitor_signals; +- } +- +- bool +- MonitorProcess () const +- { +- if (m_monitor_callback && ProcessIDIsValid()) +- { +- Host::StartMonitoringChildProcess (m_monitor_callback, +- m_monitor_callback_baton, +- GetProcessID(), +- m_monitor_signals); +- return true; +- } +- return false; +- } +- +- lldb_utility::PseudoTerminal & +- GetPTY () +- { +- return m_pty; +- } +- +-protected: +- std::string m_working_dir; +- std::string m_plugin_name; +- std::string m_shell; +- Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags +- std::vector m_file_actions; // File actions for any other files +- lldb_utility::PseudoTerminal m_pty; +- uint32_t m_resume_count; // How many times do we resume after launching +- Host::MonitorChildProcessCallback m_monitor_callback; +- void *m_monitor_callback_baton; +- bool m_monitor_signals; +- +-}; +- +-//---------------------------------------------------------------------- +-// ProcessLaunchInfo +-// +-// Describes any information that is required to launch a process. +-//---------------------------------------------------------------------- +- +-class ProcessAttachInfo : public ProcessInstanceInfo +-{ +-public: +- ProcessAttachInfo() : +- ProcessInstanceInfo(), +- m_plugin_name (), +- m_resume_count (0), +- m_wait_for_launch (false), +- m_ignore_existing (true), +- m_continue_once_attached (false) +- { +- } +- +- ProcessAttachInfo (const ProcessLaunchInfo &launch_info) : +- ProcessInstanceInfo(), +- m_plugin_name (), +- m_resume_count (0), +- m_wait_for_launch (false), +- m_ignore_existing (true), +- m_continue_once_attached (false) +- { +- ProcessInfo::operator= (launch_info); +- SetProcessPluginName (launch_info.GetProcessPluginName()); +- SetResumeCount (launch_info.GetResumeCount()); +- } +- +- bool +- GetWaitForLaunch () const +- { +- return m_wait_for_launch; +- } +- +- void +- SetWaitForLaunch (bool b) +- { +- m_wait_for_launch = b; +- } +- +- bool +- GetIgnoreExisting () const +- { +- return m_ignore_existing; +- } +- +- void +- SetIgnoreExisting (bool b) +- { +- m_ignore_existing = b; +- } +- +- bool +- GetContinueOnceAttached () const +- { +- return m_continue_once_attached; +- } +- +- void +- SetContinueOnceAttached (bool b) +- { +- m_continue_once_attached = b; +- } +- +- uint32_t +- GetResumeCount () const +- { +- return m_resume_count; +- } +- +- void +- SetResumeCount (uint32_t c) +- { +- m_resume_count = c; +- } +- +- const char * +- GetProcessPluginName () const +- { +- if (m_plugin_name.empty()) +- return NULL; +- return m_plugin_name.c_str(); +- } +- +- void +- SetProcessPluginName (const char *plugin) +- { +- if (plugin && plugin[0]) +- m_plugin_name.assign (plugin); +- else +- m_plugin_name.clear(); +- } +- +- void +- Clear () +- { +- ProcessInstanceInfo::Clear(); +- m_plugin_name.clear(); +- m_resume_count = 0; +- m_wait_for_launch = false; +- m_ignore_existing = true; +- m_continue_once_attached = false; +- } +- +- bool +- ProcessInfoSpecified () const +- { +- if (GetExecutableFile()) +- return true; +- if (GetProcessID() != LLDB_INVALID_PROCESS_ID) +- return true; +- if (GetParentProcessID() != LLDB_INVALID_PROCESS_ID) +- return true; +- return false; +- } +-protected: +- std::string m_plugin_name; +- uint32_t m_resume_count; // How many times do we resume after launching +- bool m_wait_for_launch; +- bool m_ignore_existing; +- bool m_continue_once_attached; // Supports the use-case scenario of immediately continuing the process once attached. +-}; +- +-class ProcessLaunchCommandOptions : public Options +-{ +-public: +- +- ProcessLaunchCommandOptions (CommandInterpreter &interpreter) : +- Options(interpreter) +- { +- // Keep default values of all options in one place: OptionParsingStarting () +- OptionParsingStarting (); +- } +- +- ~ProcessLaunchCommandOptions () +- { +- } +- +- Error +- SetOptionValue (uint32_t option_idx, const char *option_arg); +- +- void +- OptionParsingStarting () +- { +- launch_info.Clear(); +- } +- +- const OptionDefinition* +- GetDefinitions () +- { +- return g_option_table; +- } +- +- // Options table: Required for subclasses of Options. +- +- static OptionDefinition g_option_table[]; +- +- // Instance variables to hold the values for command options. +- +- ProcessLaunchInfo launch_info; +-}; +- +-//---------------------------------------------------------------------- +-// ProcessInstanceInfoMatch +-// +-// A class to help matching one ProcessInstanceInfo to another. +-//---------------------------------------------------------------------- +- +-class ProcessInstanceInfoMatch +-{ +-public: +- ProcessInstanceInfoMatch () : +- m_match_info (), +- m_name_match_type (eNameMatchIgnore), +- m_match_all_users (false) +- { +- } +- +- ProcessInstanceInfoMatch (const char *process_name, +- NameMatchType process_name_match_type) : +- m_match_info (), +- m_name_match_type (process_name_match_type), +- m_match_all_users (false) +- { +- m_match_info.GetExecutableFile().SetFile(process_name, false); +- } +- +- ProcessInstanceInfo & +- GetProcessInfo () +- { +- return m_match_info; +- } +- +- const ProcessInstanceInfo & +- GetProcessInfo () const +- { +- return m_match_info; +- } +- +- bool +- GetMatchAllUsers () const +- { +- return m_match_all_users; +- } +- +- void +- SetMatchAllUsers (bool b) +- { +- m_match_all_users = b; +- } +- +- NameMatchType +- GetNameMatchType () const +- { +- return m_name_match_type; +- } +- +- void +- SetNameMatchType (NameMatchType name_match_type) +- { +- m_name_match_type = name_match_type; +- } +- +- bool +- NameMatches (const char *process_name) const; +- +- bool +- Matches (const ProcessInstanceInfo &proc_info) const; +- +- bool +- MatchAllProcesses () const; +- void +- Clear (); +- +-protected: +- ProcessInstanceInfo m_match_info; +- NameMatchType m_name_match_type; +- bool m_match_all_users; +-}; +- +-class ProcessInstanceInfoList +-{ +-public: +- ProcessInstanceInfoList () : +- m_infos() +- { +- } +- +- void +- Clear() +- { +- m_infos.clear(); +- } +- +- size_t +- GetSize() +- { +- return m_infos.size(); +- } +- +- void +- Append (const ProcessInstanceInfo &info) +- { +- m_infos.push_back (info); +- } +- +- const char * +- GetProcessNameAtIndex (size_t idx) +- { +- if (idx < m_infos.size()) +- return m_infos[idx].GetName(); +- return NULL; +- } +- +- size_t +- GetProcessNameLengthAtIndex (size_t idx) +- { +- if (idx < m_infos.size()) +- return m_infos[idx].GetNameLength(); +- return 0; +- } +- +- lldb::pid_t +- GetProcessIDAtIndex (size_t idx) +- { +- if (idx < m_infos.size()) +- return m_infos[idx].GetProcessID(); +- return 0; +- } +- +- bool +- GetInfoAtIndex (size_t idx, ProcessInstanceInfo &info) +- { +- if (idx < m_infos.size()) +- { +- info = m_infos[idx]; +- return true; +- } +- return false; +- } +- +- // You must ensure "idx" is valid before calling this function +- const ProcessInstanceInfo & +- GetProcessInfoAtIndex (size_t idx) const +- { +- assert (idx < m_infos.size()); +- return m_infos[idx]; +- } +- +-protected: +- typedef std::vector collection; +- collection m_infos; +-}; +- +- +-// This class tracks the Modification state of the process. Things that can currently modify +-// the program are running the program (which will up the StopID) and writing memory (which +-// will up the MemoryID.) +-// FIXME: Should we also include modification of register states? +- +-class ProcessModID +-{ +-friend bool operator== (const ProcessModID &lhs, const ProcessModID &rhs); +-public: +- ProcessModID () : +- m_stop_id (0), +- m_last_natural_stop_id(0), +- m_resume_id (0), +- m_memory_id (0), +- m_last_user_expression_resume (0), +- m_running_user_expression (false) +- {} +- +- ProcessModID (const ProcessModID &rhs) : +- m_stop_id (rhs.m_stop_id), +- m_memory_id (rhs.m_memory_id) +- {} +- +- const ProcessModID & operator= (const ProcessModID &rhs) +- { +- if (this != &rhs) +- { +- m_stop_id = rhs.m_stop_id; +- m_memory_id = rhs.m_memory_id; +- } +- return *this; +- } +- +- ~ProcessModID () {} +- +- void BumpStopID () { +- m_stop_id++; +- if (!IsLastResumeForUserExpression()) +- m_last_natural_stop_id++; +- } +- +- void BumpMemoryID () { m_memory_id++; } +- +- void BumpResumeID () { +- m_resume_id++; +- if (m_running_user_expression > 0) +- m_last_user_expression_resume = m_resume_id; +- } +- +- uint32_t GetStopID() const { return m_stop_id; } +- uint32_t GetLastNaturalStopID() const { return m_last_natural_stop_id; } +- uint32_t GetMemoryID () const { return m_memory_id; } +- uint32_t GetResumeID () const { return m_resume_id; } +- uint32_t GetLastUserExpressionResumeID () const { return m_last_user_expression_resume; } +- +- bool MemoryIDEqual (const ProcessModID &compare) const +- { +- return m_memory_id == compare.m_memory_id; +- } +- +- bool StopIDEqual (const ProcessModID &compare) const +- { +- return m_stop_id == compare.m_stop_id; +- } +- +- void SetInvalid () +- { +- m_stop_id = UINT32_MAX; +- } +- +- bool IsValid () const +- { +- return m_stop_id != UINT32_MAX; +- } +- +- bool +- IsLastResumeForUserExpression () const +- { +- return m_resume_id == m_last_user_expression_resume; +- } +- +- void +- SetRunningUserExpression (bool on) +- { +- // REMOVEME printf ("Setting running user expression %s at resume id %d - value: %d.\n", on ? "on" : "off", m_resume_id, m_running_user_expression); +- if (on) +- m_running_user_expression++; +- else +- m_running_user_expression--; +- } +- +-private: +- uint32_t m_stop_id; +- uint32_t m_last_natural_stop_id; +- uint32_t m_resume_id; +- uint32_t m_memory_id; +- uint32_t m_last_user_expression_resume; +- uint32_t m_running_user_expression; +-}; +-inline bool operator== (const ProcessModID &lhs, const ProcessModID &rhs) +-{ +- if (lhs.StopIDEqual (rhs) +- && lhs.MemoryIDEqual (rhs)) +- return true; +- else +- return false; +-} +- +-inline bool operator!= (const ProcessModID &lhs, const ProcessModID &rhs) +-{ +- if (!lhs.StopIDEqual (rhs) +- || !lhs.MemoryIDEqual (rhs)) +- return true; +- else +- return false; +-} +- +-class MemoryRegionInfo +-{ +-public: +- typedef Range RangeType; +- +- enum OptionalBool { +- eDontKnow = -1, +- eNo = 0, +- eYes = 1 +- }; +- +- MemoryRegionInfo () : +- m_range (), +- m_read (eDontKnow), +- m_write (eDontKnow), +- m_execute (eDontKnow) +- { +- } +- +- ~MemoryRegionInfo () +- { +- } +- +- RangeType & +- GetRange() +- { +- return m_range; +- } +- +- void +- Clear() +- { +- m_range.Clear(); +- m_read = m_write = m_execute = eDontKnow; +- } +- +- const RangeType & +- GetRange() const +- { +- return m_range; +- } +- +- OptionalBool +- GetReadable () const +- { +- return m_read; +- } +- +- OptionalBool +- GetWritable () const +- { +- return m_write; +- } +- +- OptionalBool +- GetExecutable () const +- { +- return m_execute; +- } +- +- void +- SetReadable (OptionalBool val) +- { +- m_read = val; +- } +- +- void +- SetWritable (OptionalBool val) +- { +- m_write = val; +- } +- +- void +- SetExecutable (OptionalBool val) +- { +- m_execute = val; +- } +- +-protected: +- RangeType m_range; +- OptionalBool m_read; +- OptionalBool m_write; +- OptionalBool m_execute; +-}; +- +-//---------------------------------------------------------------------- +-/// @class Process Process.h "lldb/Target/Process.h" +-/// @brief A plug-in interface definition class for debugging a process. +-//---------------------------------------------------------------------- +-class Process : +- public std::enable_shared_from_this, +- public ProcessProperties, +- public UserID, +- public Broadcaster, +- public ExecutionContextScope, +- public PluginInterface +-{ +-friend class ThreadList; +-friend class ClangFunction; // For WaitForStateChangeEventsPrivate +-friend class CommandObjectProcessLaunch; +-friend class ProcessEventData; +-friend class CommandObjectBreakpointCommand; +-friend class StopInfo; +- +-public: +- +- //------------------------------------------------------------------ +- /// Broadcaster event bits definitions. +- //------------------------------------------------------------------ +- enum +- { +- eBroadcastBitStateChanged = (1 << 0), +- eBroadcastBitInterrupt = (1 << 1), +- eBroadcastBitSTDOUT = (1 << 2), +- eBroadcastBitSTDERR = (1 << 3), +- eBroadcastBitProfileData = (1 << 4) +- }; +- +- enum +- { +- eBroadcastInternalStateControlStop = (1<<0), +- eBroadcastInternalStateControlPause = (1<<1), +- eBroadcastInternalStateControlResume = (1<<2) +- }; +- +- typedef Range LoadRange; +- // We use a read/write lock to allow on or more clients to +- // access the process state while the process is stopped (reader). +- // We lock the write lock to control access to the process +- // while it is running (readers, or clients that want the process +- // stopped can block waiting for the process to stop, or just +- // try to lock it to see if they can immediately access the stopped +- // process. If the try read lock fails, then the process is running. +- typedef ReadWriteLock::ReadLocker StopLocker; +- typedef ReadWriteLock::WriteLocker RunLocker; +- +- // These two functions fill out the Broadcaster interface: +- +- static ConstString &GetStaticBroadcasterClass (); +- +- virtual ConstString &GetBroadcasterClass() const +- { +- return GetStaticBroadcasterClass(); +- } +- +- +- //------------------------------------------------------------------ +- /// A notification structure that can be used by clients to listen +- /// for changes in a process's lifetime. +- /// +- /// @see RegisterNotificationCallbacks (const Notifications&) +- /// @see UnregisterNotificationCallbacks (const Notifications&) +- //------------------------------------------------------------------ +-#ifndef SWIG +- typedef struct +- { +- void *baton; +- void (*initialize)(void *baton, Process *process); +- void (*process_state_changed) (void *baton, Process *process, lldb::StateType state); +- } Notifications; +- +- class ProcessEventData : +- public EventData +- { +- friend class Process; +- +- public: +- ProcessEventData (); +- ProcessEventData (const lldb::ProcessSP &process, lldb::StateType state); +- +- virtual ~ProcessEventData(); +- +- static const ConstString & +- GetFlavorString (); +- +- virtual const ConstString & +- GetFlavor () const; +- +- const lldb::ProcessSP & +- GetProcessSP() const +- { +- return m_process_sp; +- } +- lldb::StateType +- GetState() const +- { +- return m_state; +- } +- bool +- GetRestarted () const +- { +- return m_restarted; +- } +- +- size_t +- GetNumRestartedReasons () +- { +- return m_restarted_reasons.size(); +- } +- +- const char * +- GetRestartedReasonAtIndex(size_t idx) +- { +- if (idx > m_restarted_reasons.size()) +- return NULL; +- else +- return m_restarted_reasons[idx].c_str(); +- } +- +- bool +- GetInterrupted () const +- { +- return m_interrupted; +- } +- +- virtual void +- Dump (Stream *s) const; +- +- virtual void +- DoOnRemoval (Event *event_ptr); +- +- static const Process::ProcessEventData * +- GetEventDataFromEvent (const Event *event_ptr); +- +- static lldb::ProcessSP +- GetProcessFromEvent (const Event *event_ptr); +- +- static lldb::StateType +- GetStateFromEvent (const Event *event_ptr); +- +- static bool +- GetRestartedFromEvent (const Event *event_ptr); +- +- static size_t +- GetNumRestartedReasons(const Event *event_ptr); +- +- static const char * +- GetRestartedReasonAtIndex(const Event *event_ptr, size_t idx); +- +- static void +- AddRestartedReason (Event *event_ptr, const char *reason); +- +- static void +- SetRestartedInEvent (Event *event_ptr, bool new_value); +- +- static bool +- GetInterruptedFromEvent (const Event *event_ptr); +- +- static void +- SetInterruptedInEvent (Event *event_ptr, bool new_value); +- +- static bool +- SetUpdateStateOnRemoval (Event *event_ptr); +- +- private: +- +- void +- SetUpdateStateOnRemoval() +- { +- m_update_state++; +- } +- void +- SetRestarted (bool new_value) +- { +- m_restarted = new_value; +- } +- void +- SetInterrupted (bool new_value) +- { +- m_interrupted = new_value; +- } +- void +- AddRestartedReason (const char *reason) +- { +- m_restarted_reasons.push_back(reason); +- } +- +- lldb::ProcessSP m_process_sp; +- lldb::StateType m_state; +- std::vector m_restarted_reasons; +- bool m_restarted; // For "eStateStopped" events, this is true if the target was automatically restarted. +- int m_update_state; +- bool m_interrupted; +- DISALLOW_COPY_AND_ASSIGN (ProcessEventData); +- +- }; +- +-#endif +- +- static void +- SettingsInitialize (); +- +- static void +- SettingsTerminate (); +- +- static const ProcessPropertiesSP & +- GetGlobalProperties(); +- +- //------------------------------------------------------------------ +- /// Construct with a shared pointer to a target, and the Process listener. +- //------------------------------------------------------------------ +- Process(Target &target, Listener &listener); +- +- //------------------------------------------------------------------ +- /// Destructor. +- /// +- /// The destructor is virtual since this class is designed to be +- /// inherited from by the plug-in instance. +- //------------------------------------------------------------------ +- virtual +- ~Process(); +- +- //------------------------------------------------------------------ +- /// Find a Process plug-in that can debug \a module using the +- /// currently selected architecture. +- /// +- /// Scans all loaded plug-in interfaces that implement versions of +- /// the Process plug-in interface and returns the first instance +- /// that can debug the file. +- /// +- /// @param[in] module_sp +- /// The module shared pointer that this process will debug. +- /// +- /// @param[in] plugin_name +- /// If NULL, select the best plug-in for the binary. If non-NULL +- /// then look for a plugin whose PluginInfo's name matches +- /// this string. +- /// +- /// @see Process::CanDebug () +- //------------------------------------------------------------------ +- static lldb::ProcessSP +- FindPlugin (Target &target, +- const char *plugin_name, +- Listener &listener, +- const FileSpec *crash_file_path); +- +- +- +- //------------------------------------------------------------------ +- /// Static function that can be used with the \b host function +- /// Host::StartMonitoringChildProcess (). +- /// +- /// This function can be used by lldb_private::Process subclasses +- /// when they want to watch for a local process and have its exit +- /// status automatically set when the host child process exits. +- /// Subclasses should call Host::StartMonitoringChildProcess () +- /// with: +- /// callback = Process::SetHostProcessExitStatus +- /// callback_baton = NULL +- /// pid = Process::GetID() +- /// monitor_signals = false +- //------------------------------------------------------------------ +- static bool +- SetProcessExitStatus (void *callback_baton, // The callback baton which should be set to NULL +- lldb::pid_t pid, // The process ID we want to monitor +- bool exited, +- int signo, // Zero for no signal +- int status); // Exit value of process if signal is zero +- +- lldb::ByteOrder +- GetByteOrder () const; +- +- uint32_t +- GetAddressByteSize () const; +- +- uint32_t +- GetUniqueID() const +- { +- return m_process_unique_id; +- } +- //------------------------------------------------------------------ +- /// Check if a plug-in instance can debug the file in \a module. +- /// +- /// Each plug-in is given a chance to say whether it can debug +- /// the file in \a module. If the Process plug-in instance can +- /// debug a file on the current system, it should return \b true. +- /// +- /// @return +- /// Returns \b true if this Process plug-in instance can +- /// debug the executable, \b false otherwise. +- //------------------------------------------------------------------ +- virtual bool +- CanDebug (Target &target, +- bool plugin_specified_by_name) = 0; +- +- +- //------------------------------------------------------------------ +- /// This object is about to be destroyed, do any necessary cleanup. +- /// +- /// Subclasses that override this method should always call this +- /// superclass method. +- //------------------------------------------------------------------ +- virtual void +- Finalize(); +- +- +- //------------------------------------------------------------------ +- /// Return whether this object is valid (i.e. has not been finalized.) +- /// +- /// @return +- /// Returns \b true if this Process has not been finalized +- /// and \b false otherwise. +- //------------------------------------------------------------------ +- bool +- IsValid() const +- { +- return !m_finalize_called; +- } +- +- //------------------------------------------------------------------ +- /// Return a multi-word command object that can be used to expose +- /// plug-in specific commands. +- /// +- /// This object will be used to resolve plug-in commands and can be +- /// triggered by a call to: +- /// +- /// (lldb) process commmand +- /// +- /// @return +- /// A CommandObject which can be one of the concrete subclasses +- /// of CommandObject like CommandObjectRaw, CommandObjectParsed, +- /// or CommandObjectMultiword. +- //------------------------------------------------------------------ +- virtual CommandObject * +- GetPluginCommandObject() +- { +- return NULL; +- } +- +- //------------------------------------------------------------------ +- /// Launch a new process. +- /// +- /// Launch a new process by spawning a new process using the +- /// target object's executable module's file as the file to launch. +- /// Arguments are given in \a argv, and the environment variables +- /// are in \a envp. Standard input and output files can be +- /// optionally re-directed to \a stdin_path, \a stdout_path, and +- /// \a stderr_path. +- /// +- /// This function is not meant to be overridden by Process +- /// subclasses. It will first call Process::WillLaunch (Module *) +- /// and if that returns \b true, Process::DoLaunch (Module*, +- /// char const *[],char const *[],const char *,const char *, +- /// const char *) will be called to actually do the launching. If +- /// DoLaunch returns \b true, then Process::DidLaunch() will be +- /// called. +- /// +- /// @param[in] argv +- /// The argument array. +- /// +- /// @param[in] envp +- /// The environment array. +- /// +- /// @param[in] launch_flags +- /// Flags to modify the launch (@see lldb::LaunchFlags) +- /// +- /// @param[in] stdin_path +- /// The path to use when re-directing the STDIN of the new +- /// process. If all stdXX_path arguments are NULL, a pseudo +- /// terminal will be used. +- /// +- /// @param[in] stdout_path +- /// The path to use when re-directing the STDOUT of the new +- /// process. If all stdXX_path arguments are NULL, a pseudo +- /// terminal will be used. +- /// +- /// @param[in] stderr_path +- /// The path to use when re-directing the STDERR of the new +- /// process. If all stdXX_path arguments are NULL, a pseudo +- /// terminal will be used. +- /// +- /// @param[in] working_directory +- /// The working directory to have the child process run in +- /// +- /// @return +- /// An error object. Call GetID() to get the process ID if +- /// the error object is success. +- //------------------------------------------------------------------ +- virtual Error +- Launch (const ProcessLaunchInfo &launch_info); +- +- virtual Error +- LoadCore (); +- +- virtual Error +- DoLoadCore () +- { +- Error error; +- error.SetErrorStringWithFormat("error: %s does not support loading core files.", GetPluginName().GetCString()); +- return error; +- } +- +- //------------------------------------------------------------------ +- /// Get the dynamic loader plug-in for this process. +- /// +- /// The default action is to let the DynamicLoader plug-ins check +- /// the main executable and the DynamicLoader will select itself +- /// automatically. Subclasses can override this if inspecting the +- /// executable is not desired, or if Process subclasses can only +- /// use a specific DynamicLoader plug-in. +- //------------------------------------------------------------------ +- virtual DynamicLoader * +- GetDynamicLoader (); +- +- //------------------------------------------------------------------ +- /// Attach to an existing process using the process attach info. +- /// +- /// This function is not meant to be overridden by Process +- /// subclasses. It will first call WillAttach (lldb::pid_t) +- /// or WillAttach (const char *), and if that returns \b +- /// true, DoAttach (lldb::pid_t) or DoAttach (const char *) will +- /// be called to actually do the attach. If DoAttach returns \b +- /// true, then Process::DidAttach() will be called. +- /// +- /// @param[in] pid +- /// The process ID that we should attempt to attach to. +- /// +- /// @return +- /// Returns \a pid if attaching was successful, or +- /// LLDB_INVALID_PROCESS_ID if attaching fails. +- //------------------------------------------------------------------ +- virtual Error +- Attach (ProcessAttachInfo &attach_info); +- +- //------------------------------------------------------------------ +- /// Attach to a remote system via a URL +- /// +- /// @param[in] strm +- /// A stream where output intended for the user +- /// (if the driver has a way to display that) generated during +- /// the connection. This may be NULL if no output is needed.A +- /// +- /// @param[in] remote_url +- /// The URL format that we are connecting to. +- /// +- /// @return +- /// Returns an error object. +- //------------------------------------------------------------------ +- virtual Error +- ConnectRemote (Stream *strm, const char *remote_url); +- +- bool +- GetShouldDetach () const +- { +- return m_should_detach; +- } +- +- void +- SetShouldDetach (bool b) +- { +- m_should_detach = b; +- } +- +- //------------------------------------------------------------------ +- /// Get the image information address for the current process. +- /// +- /// Some runtimes have system functions that can help dynamic +- /// loaders locate the dynamic loader information needed to observe +- /// shared libraries being loaded or unloaded. This function is +- /// in the Process interface (as opposed to the DynamicLoader +- /// interface) to ensure that remote debugging can take advantage of +- /// this functionality. +- /// +- /// @return +- /// The address of the dynamic loader information, or +- /// LLDB_INVALID_ADDRESS if this is not supported by this +- /// interface. +- //------------------------------------------------------------------ +- virtual lldb::addr_t +- GetImageInfoAddress (); +- +- //------------------------------------------------------------------ +- /// Load a shared library into this process. +- /// +- /// Try and load a shared library into the current process. This +- /// call might fail in the dynamic loader plug-in says it isn't safe +- /// to try and load shared libraries at the moment. +- /// +- /// @param[in] image_spec +- /// The image file spec that points to the shared library that +- /// you want to load. +- /// +- /// @param[out] error +- /// An error object that gets filled in with any errors that +- /// might occur when trying to load the shared library. +- /// +- /// @return +- /// A token that represents the shared library that can be +- /// later used to unload the shared library. A value of +- /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared +- /// library can't be opened. +- //------------------------------------------------------------------ +- virtual uint32_t +- LoadImage (const FileSpec &image_spec, Error &error); +- +- virtual Error +- UnloadImage (uint32_t image_token); +- +- //------------------------------------------------------------------ +- /// Register for process and thread notifications. +- /// +- /// Clients can register nofication callbacks by filling out a +- /// Process::Notifications structure and calling this function. +- /// +- /// @param[in] callbacks +- /// A structure that contains the notification baton and +- /// callback functions. +- /// +- /// @see Process::Notifications +- //------------------------------------------------------------------ +-#ifndef SWIG +- void +- RegisterNotificationCallbacks (const Process::Notifications& callbacks); +-#endif +- //------------------------------------------------------------------ +- /// Unregister for process and thread notifications. +- /// +- /// Clients can unregister nofication callbacks by passing a copy of +- /// the original baton and callbacks in \a callbacks. +- /// +- /// @param[in] callbacks +- /// A structure that contains the notification baton and +- /// callback functions. +- /// +- /// @return +- /// Returns \b true if the notification callbacks were +- /// successfully removed from the process, \b false otherwise. +- /// +- /// @see Process::Notifications +- //------------------------------------------------------------------ +-#ifndef SWIG +- bool +- UnregisterNotificationCallbacks (const Process::Notifications& callbacks); +-#endif +- //================================================================== +- // Built in Process Control functions +- //================================================================== +- //------------------------------------------------------------------ +- /// Resumes all of a process's threads as configured using the +- /// Thread run control functions. +- /// +- /// Threads for a process should be updated with one of the run +- /// control actions (resume, step, or suspend) that they should take +- /// when the process is resumed. If no run control action is given +- /// to a thread it will be resumed by default. +- /// +- /// This function is not meant to be overridden by Process +- /// subclasses. This function will take care of disabling any +- /// breakpoints that threads may be stopped at, single stepping, and +- /// re-enabling breakpoints, and enabling the basic flow control +- /// that the plug-in instances need not worry about. +- /// +- /// N.B. This function also sets the Write side of the Run Lock, +- /// which is unset when the corresponding stop event is pulled off +- /// the Public Event Queue. If you need to resume the process without +- /// setting the Run Lock, use PrivateResume (though you should only do +- /// that from inside the Process class. +- /// +- /// @return +- /// Returns an error object. +- /// +- /// @see Thread:Resume() +- /// @see Thread:Step() +- /// @see Thread:Suspend() +- //------------------------------------------------------------------ +- Error +- Resume(); +- +- //------------------------------------------------------------------ +- /// Halts a running process. +- /// +- /// This function is not meant to be overridden by Process +- /// subclasses. +- /// If the process is successfully halted, a eStateStopped +- /// process event with GetInterrupted will be broadcast. If false, we will +- /// halt the process with no events generated by the halt. +- /// +- /// @param[in] clear_thread_plans +- /// If true, when the process stops, clear all thread plans. +- /// +- /// @return +- /// Returns an error object. If the error is empty, the process is halted. +- /// otherwise the halt has failed. +- //------------------------------------------------------------------ +- Error +- Halt (bool clear_thread_plans = false); +- +- //------------------------------------------------------------------ +- /// Detaches from a running or stopped process. +- /// +- /// This function is not meant to be overridden by Process +- /// subclasses. +- /// +- /// @param[in] keep_stopped +- /// If true, don't resume the process on detach. +- /// +- /// @return +- /// Returns an error object. +- //------------------------------------------------------------------ +- Error +- Detach (bool keep_stopped); +- +- //------------------------------------------------------------------ +- /// Kills the process and shuts down all threads that were spawned +- /// to track and monitor the process. +- /// +- /// This function is not meant to be overridden by Process +- /// subclasses. +- /// +- /// @return +- /// Returns an error object. +- //------------------------------------------------------------------ +- Error +- Destroy(); +- +- //------------------------------------------------------------------ +- /// Sends a process a UNIX signal \a signal. +- /// +- /// This function is not meant to be overridden by Process +- /// subclasses. +- /// +- /// @return +- /// Returns an error object. +- //------------------------------------------------------------------ +- Error +- Signal (int signal); +- +- virtual UnixSignals & +- GetUnixSignals () +- { +- return m_unix_signals; +- } +- +- //================================================================== +- // Plug-in Process Control Overrides +- //================================================================== +- +- //------------------------------------------------------------------ +- /// Called before attaching to a process. +- /// +- /// Allow Process plug-ins to execute some code before attaching a +- /// process. +- /// +- /// @return +- /// Returns an error object. +- //------------------------------------------------------------------ +- virtual Error +- WillAttachToProcessWithID (lldb::pid_t pid) +- { +- return Error(); +- } +- +- //------------------------------------------------------------------ +- /// Called before attaching to a process. +- /// +- /// Allow Process plug-ins to execute some code before attaching a +- /// process. +- /// +- /// @return +- /// Returns an error object. +- //------------------------------------------------------------------ +- virtual Error +- WillAttachToProcessWithName (const char *process_name, bool wait_for_launch) +- { +- return Error(); +- } +- +- //------------------------------------------------------------------ +- /// Attach to a remote system via a URL +- /// +- /// @param[in] strm +- /// A stream where output intended for the user +- /// (if the driver has a way to display that) generated during +- /// the connection. This may be NULL if no output is needed.A +- /// +- /// @param[in] remote_url +- /// The URL format that we are connecting to. +- /// +- /// @return +- /// Returns an error object. +- //------------------------------------------------------------------ +- virtual Error +- DoConnectRemote (Stream *strm, const char *remote_url) +- { +- Error error; +- error.SetErrorString ("remote connections are not supported"); +- return error; +- } +- +- //------------------------------------------------------------------ +- /// Attach to an existing process using a process ID. +- /// +- /// @param[in] pid +- /// The process ID that we should attempt to attach to. +- /// +- /// @return +- /// Returns \a pid if attaching was successful, or +- /// LLDB_INVALID_PROCESS_ID if attaching fails. +- //------------------------------------------------------------------ +- virtual Error +- DoAttachToProcessWithID (lldb::pid_t pid) +- { +- Error error; +- error.SetErrorStringWithFormat("error: %s does not support attaching to a process by pid", GetPluginName().GetCString()); +- return error; +- } +- +- //------------------------------------------------------------------ +- /// Attach to an existing process using a process ID. +- /// +- /// @param[in] pid +- /// The process ID that we should attempt to attach to. +- /// +- /// @param[in] attach_info +- /// Information on how to do the attach. For example, GetUserID() +- /// will return the uid to attach as. +- /// +- /// @return +- /// Returns \a pid if attaching was successful, or +- /// LLDB_INVALID_PROCESS_ID if attaching fails. +- /// hanming : need flag +- //------------------------------------------------------------------ +- virtual Error +- DoAttachToProcessWithID (lldb::pid_t pid, const ProcessAttachInfo &attach_info) +- { +- Error error; +- error.SetErrorStringWithFormat("error: %s does not support attaching to a process by pid", GetPluginName().GetCString()); +- return error; +- } +- +- //------------------------------------------------------------------ +- /// Attach to an existing process using a partial process name. +- /// +- /// @param[in] process_name +- /// The name of the process to attach to. +- /// +- /// @param[in] wait_for_launch +- /// If \b true, wait for the process to be launched and attach +- /// as soon as possible after it does launch. If \b false, then +- /// search for a matching process the currently exists. +- /// +- /// @param[in] attach_info +- /// Information on how to do the attach. For example, GetUserID() +- /// will return the uid to attach as. +- /// +- /// @return +- /// Returns \a pid if attaching was successful, or +- /// LLDB_INVALID_PROCESS_ID if attaching fails. +- //------------------------------------------------------------------ +- virtual Error +- DoAttachToProcessWithName (const char *process_name, bool wait_for_launch, const ProcessAttachInfo &attach_info) +- { +- Error error; +- error.SetErrorString("attach by name is not supported"); +- return error; +- } +- +- //------------------------------------------------------------------ +- /// Called after attaching a process. +- /// +- /// Allow Process plug-ins to execute some code after attaching to +- /// a process. +- //------------------------------------------------------------------ +- virtual void +- DidAttach () {} +- +- +- //------------------------------------------------------------------ +- /// Called after a process re-execs itself. +- /// +- /// Allow Process plug-ins to execute some code after a process has +- /// exec'ed itself. Subclasses typically should override DoDidExec() +- /// as the lldb_private::Process class needs to remove its dynamic +- /// loader, runtime, ABI and other plug-ins, as well as unload all +- /// shared libraries. +- //------------------------------------------------------------------ +- virtual void +- DidExec (); +- +- //------------------------------------------------------------------ +- /// Subclasses of Process should implement this function if they +- /// need to do anything after a process exec's itself. +- //------------------------------------------------------------------ +- virtual void +- DoDidExec () +- { +- } +- +- //------------------------------------------------------------------ +- /// Called before launching to a process. +- /// +- /// Allow Process plug-ins to execute some code before launching a +- /// process. +- /// +- /// @return +- /// Returns an error object. +- //------------------------------------------------------------------ +- virtual Error +- WillLaunch (Module* module) +- { +- return Error(); +- } +- +- //------------------------------------------------------------------ +- /// Launch a new process. +- /// +- /// Launch a new process by spawning a new process using \a module's +- /// file as the file to launch. Arguments are given in \a argv, +- /// and the environment variables are in \a envp. Standard input +- /// and output files can be optionally re-directed to \a stdin_path, +- /// \a stdout_path, and \a stderr_path. +- /// +- /// @param[in] module +- /// The module from which to extract the file specification and +- /// launch. +- /// +- /// @param[in] argv +- /// The argument array. +- /// +- /// @param[in] envp +- /// The environment array. +- /// +- /// @param[in] launch_flags +- /// Flags to modify the launch (@see lldb::LaunchFlags) +- /// +- /// @param[in] stdin_path +- /// The path to use when re-directing the STDIN of the new +- /// process. If all stdXX_path arguments are NULL, a pseudo +- /// terminal will be used. +- /// +- /// @param[in] stdout_path +- /// The path to use when re-directing the STDOUT of the new +- /// process. If all stdXX_path arguments are NULL, a pseudo +- /// terminal will be used. +- /// +- /// @param[in] stderr_path +- /// The path to use when re-directing the STDERR of the new +- /// process. If all stdXX_path arguments are NULL, a pseudo +- /// terminal will be used. +- /// +- /// @param[in] working_directory +- /// The working directory to have the child process run in +- /// +- /// @return +- /// A new valid process ID, or LLDB_INVALID_PROCESS_ID if +- /// launching fails. +- //------------------------------------------------------------------ +- virtual Error +- DoLaunch (Module *exe_module, +- const ProcessLaunchInfo &launch_info) +- { +- Error error; +- error.SetErrorStringWithFormat("error: %s does not support launching processes", GetPluginName().GetCString()); +- return error; +- } +- +- +- //------------------------------------------------------------------ +- /// Called after launching a process. +- /// +- /// Allow Process plug-ins to execute some code after launching +- /// a process. +- //------------------------------------------------------------------ +- virtual void +- DidLaunch () {} +- +- +- +- //------------------------------------------------------------------ +- /// Called before resuming to a process. +- /// +- /// Allow Process plug-ins to execute some code before resuming a +- /// process. +- /// +- /// @return +- /// Returns an error object. +- //------------------------------------------------------------------ +- virtual Error +- WillResume () { return Error(); } +- +- //------------------------------------------------------------------ +- /// Resumes all of a process's threads as configured using the +- /// Thread run control functions. +- /// +- /// Threads for a process should be updated with one of the run +- /// control actions (resume, step, or suspend) that they should take +- /// when the process is resumed. If no run control action is given +- /// to a thread it will be resumed by default. +- /// +- /// @return +- /// Returns \b true if the process successfully resumes using +- /// the thread run control actions, \b false otherwise. +- /// +- /// @see Thread:Resume() +- /// @see Thread:Step() +- /// @see Thread:Suspend() +- //------------------------------------------------------------------ +- virtual Error +- DoResume () +- { +- Error error; +- error.SetErrorStringWithFormat("error: %s does not support resuming processes", GetPluginName().GetCString()); +- return error; +- } +- +- +- //------------------------------------------------------------------ +- /// Called after resuming a process. +- /// +- /// Allow Process plug-ins to execute some code after resuming +- /// a process. +- //------------------------------------------------------------------ +- virtual void +- DidResume () {} +- +- +- //------------------------------------------------------------------ +- /// Called before halting to a process. +- /// +- /// Allow Process plug-ins to execute some code before halting a +- /// process. +- /// +- /// @return +- /// Returns an error object. +- //------------------------------------------------------------------ +- virtual Error +- WillHalt () { return Error(); } +- +- //------------------------------------------------------------------ +- /// Halts a running process. +- /// +- /// DoHalt must produce one and only one stop StateChanged event if it actually +- /// stops the process. If the stop happens through some natural event (for +- /// instance a SIGSTOP), then forwarding that event will do. Otherwise, you must +- /// generate the event manually. Note also, the private event thread is stopped when +- /// DoHalt is run to prevent the events generated while halting to trigger +- /// other state changes before the halt is complete. +- /// +- /// @param[out] caused_stop +- /// If true, then this Halt caused the stop, otherwise, the +- /// process was already stopped. +- /// +- /// @return +- /// Returns \b true if the process successfully halts, \b false +- /// otherwise. +- //------------------------------------------------------------------ +- virtual Error +- DoHalt (bool &caused_stop) +- { +- Error error; +- error.SetErrorStringWithFormat("error: %s does not support halting processes", GetPluginName().GetCString()); +- return error; +- } +- +- +- //------------------------------------------------------------------ +- /// Called after halting a process. +- /// +- /// Allow Process plug-ins to execute some code after halting +- /// a process. +- //------------------------------------------------------------------ +- virtual void +- DidHalt () {} +- +- //------------------------------------------------------------------ +- /// Called before detaching from a process. +- /// +- /// Allow Process plug-ins to execute some code before detaching +- /// from a process. +- /// +- /// @return +- /// Returns an error object. +- //------------------------------------------------------------------ +- virtual Error +- WillDetach () +- { +- return Error(); +- } +- +- //------------------------------------------------------------------ +- /// Detaches from a running or stopped process. +- /// +- /// @return +- /// Returns \b true if the process successfully detaches, \b +- /// false otherwise. +- //------------------------------------------------------------------ +- virtual Error +- DoDetach (bool keep_stopped) +- { +- Error error; +- error.SetErrorStringWithFormat("error: %s does not support detaching from processes", GetPluginName().GetCString()); +- return error; +- } +- +- +- //------------------------------------------------------------------ +- /// Called after detaching from a process. +- /// +- /// Allow Process plug-ins to execute some code after detaching +- /// from a process. +- //------------------------------------------------------------------ +- virtual void +- DidDetach () {} +- +- virtual bool +- DetachRequiresHalt() { return false; } +- +- //------------------------------------------------------------------ +- /// Called before sending a signal to a process. +- /// +- /// Allow Process plug-ins to execute some code before sending a +- /// signal to a process. +- /// +- /// @return +- /// Returns no error if it is safe to proceed with a call to +- /// Process::DoSignal(int), otherwise an error describing what +- /// prevents the signal from being sent. +- //------------------------------------------------------------------ +- virtual Error +- WillSignal () { return Error(); } +- +- //------------------------------------------------------------------ +- /// Sends a process a UNIX signal \a signal. +- /// +- /// @return +- /// Returns an error object. +- //------------------------------------------------------------------ +- virtual Error +- DoSignal (int signal) +- { +- Error error; +- error.SetErrorStringWithFormat("error: %s does not support senging signals to processes", GetPluginName().GetCString()); +- return error; +- } +- +- virtual Error +- WillDestroy () { return Error(); } +- +- virtual Error +- DoDestroy () = 0; +- +- virtual void +- DidDestroy () { } +- +- virtual bool +- DestroyRequiresHalt() { return true; } +- +- +- //------------------------------------------------------------------ +- /// Called after sending a signal to a process. +- /// +- /// Allow Process plug-ins to execute some code after sending a +- /// signal to a process. +- //------------------------------------------------------------------ +- virtual void +- DidSignal () {} +- +- //------------------------------------------------------------------ +- /// Currently called as part of ShouldStop. +- /// FIXME: Should really happen when the target stops before the +- /// event is taken from the queue... +- /// +- /// This callback is called as the event +- /// is about to be queued up to allow Process plug-ins to execute +- /// some code prior to clients being notified that a process was +- /// stopped. Common operations include updating the thread list, +- /// invalidating any thread state (registers, stack, etc) prior to +- /// letting the notification go out. +- /// +- //------------------------------------------------------------------ +- virtual void +- RefreshStateAfterStop () = 0; +- +- //------------------------------------------------------------------ +- /// Get the target object pointer for this module. +- /// +- /// @return +- /// A Target object pointer to the target that owns this +- /// module. +- //------------------------------------------------------------------ +- Target & +- GetTarget () +- { +- return m_target; +- } +- +- //------------------------------------------------------------------ +- /// Get the const target object pointer for this module. +- /// +- /// @return +- /// A const Target object pointer to the target that owns this +- /// module. +- //------------------------------------------------------------------ +- const Target & +- GetTarget () const +- { +- return m_target; +- } +- +- //------------------------------------------------------------------ +- /// Flush all data in the process. +- /// +- /// Flush the memory caches, all threads, and any other cached data +- /// in the process. +- /// +- /// This function can be called after a world changing event like +- /// adding a new symbol file, or after the process makes a large +- /// context switch (from boot ROM to booted into an OS). +- //------------------------------------------------------------------ +- void +- Flush (); +- +- //------------------------------------------------------------------ +- /// Get accessor for the current process state. +- /// +- /// @return +- /// The current state of the process. +- /// +- /// @see lldb::StateType +- //------------------------------------------------------------------ +- lldb::StateType +- GetState (); +- +- ExecutionResults +- RunThreadPlan (ExecutionContext &exe_ctx, +- lldb::ThreadPlanSP &thread_plan_sp, +- bool stop_others, +- bool run_others, +- bool unwind_on_error, +- bool ignore_breakpoints, +- uint32_t timeout_usec, +- Stream &errors); +- +- static const char * +- ExecutionResultAsCString (ExecutionResults result); +- +- void +- GetStatus (Stream &ostrm); +- +- size_t +- GetThreadStatus (Stream &ostrm, +- bool only_threads_with_stop_reason, +- uint32_t start_frame, +- uint32_t num_frames, +- uint32_t num_frames_with_source); +- +- void +- SendAsyncInterrupt (); +- +-protected: +- +- void +- SetState (lldb::EventSP &event_sp); +- +- lldb::StateType +- GetPrivateState (); +- +- //------------------------------------------------------------------ +- /// The "private" side of resuming a process. This doesn't alter the +- /// state of m_run_lock, but just causes the process to resume. +- /// +- /// @return +- /// An Error object describing the success or failure of the resume. +- //------------------------------------------------------------------ +- Error +- PrivateResume (); +- +- //------------------------------------------------------------------ +- // Called internally +- //------------------------------------------------------------------ +- void +- CompleteAttach (); +- +-public: +- //------------------------------------------------------------------ +- /// Get the exit status for a process. +- /// +- /// @return +- /// The process's return code, or -1 if the current process +- /// state is not eStateExited. +- //------------------------------------------------------------------ +- int +- GetExitStatus (); +- +- //------------------------------------------------------------------ +- /// Get a textual description of what the process exited. +- /// +- /// @return +- /// The textual description of why the process exited, or NULL +- /// if there is no description available. +- //------------------------------------------------------------------ +- const char * +- GetExitDescription (); +- +- +- virtual void +- DidExit () +- { +- } +- +- //------------------------------------------------------------------ +- /// Get the Modification ID of the process. +- /// +- /// @return +- /// The modification ID of the process. +- //------------------------------------------------------------------ +- ProcessModID +- GetModID () const +- { +- return m_mod_id; +- } +- +- const ProcessModID & +- GetModIDRef () const +- { +- return m_mod_id; +- } +- +- uint32_t +- GetStopID () const +- { +- return m_mod_id.GetStopID(); +- } +- +- uint32_t +- GetResumeID () const +- { +- return m_mod_id.GetResumeID(); +- } +- +- uint32_t +- GetLastUserExpressionResumeID () const +- { +- return m_mod_id.GetLastUserExpressionResumeID(); +- } +- +- uint32_t +- GetLastNaturalStopID() +- { +- return m_mod_id.GetLastNaturalStopID(); +- } +- +- //------------------------------------------------------------------ +- /// Set accessor for the process exit status (return code). +- /// +- /// Sometimes a child exits and the exit can be detected by global +- /// functions (signal handler for SIGCHLD for example). This +- /// accessor allows the exit status to be set from an external +- /// source. +- /// +- /// Setting this will cause a eStateExited event to be posted to +- /// the process event queue. +- /// +- /// @param[in] exit_status +- /// The value for the process's return code. +- /// +- /// @see lldb::StateType +- //------------------------------------------------------------------ +- virtual bool +- SetExitStatus (int exit_status, const char *cstr); +- +- //------------------------------------------------------------------ +- /// Check if a process is still alive. +- /// +- /// @return +- /// Returns \b true if the process is still valid, \b false +- /// otherwise. +- //------------------------------------------------------------------ +- virtual bool +- IsAlive () = 0; +- +- //------------------------------------------------------------------ +- /// Before lldb detaches from a process, it warns the user that they are about to lose their debug session. +- /// In some cases, this warning doesn't need to be emitted -- for instance, with core file debugging where +- /// the user can reconstruct the "state" by simply re-running the debugger on the core file. +- /// +- /// @return +- // true if the user should be warned about detaching from this process. +- //------------------------------------------------------------------ +- virtual bool +- WarnBeforeDetach () const +- { +- return true; +- } +- +- //------------------------------------------------------------------ +- /// Actually do the reading of memory from a process. +- /// +- /// Subclasses must override this function and can return fewer +- /// bytes than requested when memory requests are too large. This +- /// class will break up the memory requests and keep advancing the +- /// arguments along as needed. +- /// +- /// @param[in] vm_addr +- /// A virtual load address that indicates where to start reading +- /// memory from. +- /// +- /// @param[in] size +- /// The number of bytes to read. +- /// +- /// @param[out] buf +- /// A byte buffer that is at least \a size bytes long that +- /// will receive the memory bytes. +- /// +- /// @return +- /// The number of bytes that were actually read into \a buf. +- //------------------------------------------------------------------ +- virtual size_t +- DoReadMemory (lldb::addr_t vm_addr, +- void *buf, +- size_t size, +- Error &error) = 0; +- +- //------------------------------------------------------------------ +- /// Read of memory from a process. +- /// +- /// This function will read memory from the current process's +- /// address space and remove any traps that may have been inserted +- /// into the memory. +- /// +- /// This function is not meant to be overridden by Process +- /// subclasses, the subclasses should implement +- /// Process::DoReadMemory (lldb::addr_t, size_t, void *). +- /// +- /// @param[in] vm_addr +- /// A virtual load address that indicates where to start reading +- /// memory from. +- /// +- /// @param[out] buf +- /// A byte buffer that is at least \a size bytes long that +- /// will receive the memory bytes. +- /// +- /// @param[in] size +- /// The number of bytes to read. +- /// +- /// @return +- /// The number of bytes that were actually read into \a buf. If +- /// the returned number is greater than zero, yet less than \a +- /// size, then this function will get called again with \a +- /// vm_addr, \a buf, and \a size updated appropriately. Zero is +- /// returned to indicate an error. +- //------------------------------------------------------------------ +- virtual size_t +- ReadMemory (lldb::addr_t vm_addr, +- void *buf, +- size_t size, +- Error &error); +- +- //------------------------------------------------------------------ +- /// Read a NULL terminated string from memory +- /// +- /// This function will read a cache page at a time until a NULL +- /// string terminator is found. It will stop reading if an aligned +- /// sequence of NULL termination \a type_width bytes is not found +- /// before reading \a cstr_max_len bytes. The results are always +- /// guaranteed to be NULL terminated, and that no more than +- /// (max_bytes - type_width) bytes will be read. +- /// +- /// @param[in] vm_addr +- /// The virtual load address to start the memory read. +- /// +- /// @param[in] str +- /// A character buffer containing at least max_bytes. +- /// +- /// @param[in] max_bytes +- /// The maximum number of bytes to read. +- /// +- /// @param[in] error +- /// The error status of the read operation. +- /// +- /// @param[in] type_width +- /// The size of the null terminator (1 to 4 bytes per +- /// character). Defaults to 1. +- /// +- /// @return +- /// The error status or the number of bytes prior to the null terminator. +- //------------------------------------------------------------------ +- size_t +- ReadStringFromMemory (lldb::addr_t vm_addr, +- char *str, +- size_t max_bytes, +- Error &error, +- size_t type_width = 1); +- +- //------------------------------------------------------------------ +- /// Read a NULL terminated C string from memory +- /// +- /// This function will read a cache page at a time until the NULL +- /// C string terminator is found. It will stop reading if the NULL +- /// termination byte isn't found before reading \a cstr_max_len +- /// bytes, and the results are always guaranteed to be NULL +- /// terminated (at most cstr_max_len - 1 bytes will be read). +- //------------------------------------------------------------------ +- size_t +- ReadCStringFromMemory (lldb::addr_t vm_addr, +- char *cstr, +- size_t cstr_max_len, +- Error &error); +- +- size_t +- ReadCStringFromMemory (lldb::addr_t vm_addr, +- std::string &out_str, +- Error &error); +- +- size_t +- ReadMemoryFromInferior (lldb::addr_t vm_addr, +- void *buf, +- size_t size, +- Error &error); +- +- //------------------------------------------------------------------ +- /// Reads an unsigned integer of the specified byte size from +- /// process memory. +- /// +- /// @param[in] load_addr +- /// A load address of the integer to read. +- /// +- /// @param[in] byte_size +- /// The size in byte of the integer to read. +- /// +- /// @param[in] fail_value +- /// The value to return if we fail to read an integer. +- /// +- /// @param[out] error +- /// An error that indicates the success or failure of this +- /// operation. If error indicates success (error.Success()), +- /// then the value returned can be trusted, otherwise zero +- /// will be returned. +- /// +- /// @return +- /// The unsigned integer that was read from the process memory +- /// space. If the integer was smaller than a uint64_t, any +- /// unused upper bytes will be zero filled. If the process +- /// byte order differs from the host byte order, the integer +- /// value will be appropriately byte swapped into host byte +- /// order. +- //------------------------------------------------------------------ +- uint64_t +- ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr, +- size_t byte_size, +- uint64_t fail_value, +- Error &error); +- +- lldb::addr_t +- ReadPointerFromMemory (lldb::addr_t vm_addr, +- Error &error); +- +- bool +- WritePointerToMemory (lldb::addr_t vm_addr, +- lldb::addr_t ptr_value, +- Error &error); +- +- //------------------------------------------------------------------ +- /// Actually do the writing of memory to a process. +- /// +- /// @param[in] vm_addr +- /// A virtual load address that indicates where to start writing +- /// memory to. +- /// +- /// @param[in] buf +- /// A byte buffer that is at least \a size bytes long that +- /// contains the data to write. +- /// +- /// @param[in] size +- /// The number of bytes to write. +- /// +- /// @param[out] error +- /// An error value in case the memory write fails. +- /// +- /// @return +- /// The number of bytes that were actually written. +- //------------------------------------------------------------------ +- virtual size_t +- DoWriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error) +- { +- error.SetErrorStringWithFormat("error: %s does not support writing to processes", GetPluginName().GetCString()); +- return 0; +- } +- +- +- //------------------------------------------------------------------ +- /// Write all or part of a scalar value to memory. +- /// +- /// The value contained in \a scalar will be swapped to match the +- /// byte order of the process that is being debugged. If \a size is +- /// less than the size of scalar, the least significate \a size bytes +- /// from scalar will be written. If \a size is larger than the byte +- /// size of scalar, then the extra space will be padded with zeros +- /// and the scalar value will be placed in the least significant +- /// bytes in memory. +- /// +- /// @param[in] vm_addr +- /// A virtual load address that indicates where to start writing +- /// memory to. +- /// +- /// @param[in] scalar +- /// The scalar to write to the debugged process. +- /// +- /// @param[in] size +- /// This value can be smaller or larger than the scalar value +- /// itself. If \a size is smaller than the size of \a scalar, +- /// the least significant bytes in \a scalar will be used. If +- /// \a size is larger than the byte size of \a scalar, then +- /// the extra space will be padded with zeros. If \a size is +- /// set to UINT32_MAX, then the size of \a scalar will be used. +- /// +- /// @param[out] error +- /// An error value in case the memory write fails. +- /// +- /// @return +- /// The number of bytes that were actually written. +- //------------------------------------------------------------------ +- size_t +- WriteScalarToMemory (lldb::addr_t vm_addr, +- const Scalar &scalar, +- size_t size, +- Error &error); +- +- size_t +- ReadScalarIntegerFromMemory (lldb::addr_t addr, +- uint32_t byte_size, +- bool is_signed, +- Scalar &scalar, +- Error &error); +- +- //------------------------------------------------------------------ +- /// Write memory to a process. +- /// +- /// This function will write memory to the current process's +- /// address space and maintain any traps that might be present due +- /// to software breakpoints. +- /// +- /// This function is not meant to be overridden by Process +- /// subclasses, the subclasses should implement +- /// Process::DoWriteMemory (lldb::addr_t, size_t, void *). +- /// +- /// @param[in] vm_addr +- /// A virtual load address that indicates where to start writing +- /// memory to. +- /// +- /// @param[in] buf +- /// A byte buffer that is at least \a size bytes long that +- /// contains the data to write. +- /// +- /// @param[in] size +- /// The number of bytes to write. +- /// +- /// @return +- /// The number of bytes that were actually written. +- //------------------------------------------------------------------ +- size_t +- WriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error); +- +- +- //------------------------------------------------------------------ +- /// Actually allocate memory in the process. +- /// +- /// This function will allocate memory in the process's address +- /// space. This can't rely on the generic function calling mechanism, +- /// since that requires this function. +- /// +- /// @param[in] size +- /// The size of the allocation requested. +- /// +- /// @return +- /// The address of the allocated buffer in the process, or +- /// LLDB_INVALID_ADDRESS if the allocation failed. +- //------------------------------------------------------------------ +- +- virtual lldb::addr_t +- DoAllocateMemory (size_t size, uint32_t permissions, Error &error) +- { +- error.SetErrorStringWithFormat("error: %s does not support allocating in the debug process", GetPluginName().GetCString()); +- return LLDB_INVALID_ADDRESS; +- } +- +- +- //------------------------------------------------------------------ +- /// The public interface to allocating memory in the process. +- /// +- /// This function will allocate memory in the process's address +- /// space. This can't rely on the generic function calling mechanism, +- /// since that requires this function. +- /// +- /// @param[in] size +- /// The size of the allocation requested. +- /// +- /// @param[in] permissions +- /// Or together any of the lldb::Permissions bits. The permissions on +- /// a given memory allocation can't be changed after allocation. Note +- /// that a block that isn't set writable can still be written on from lldb, +- /// just not by the process itself. +- /// +- /// @param[in/out] error +- /// An error object to fill in if things go wrong. +- /// @return +- /// The address of the allocated buffer in the process, or +- /// LLDB_INVALID_ADDRESS if the allocation failed. +- //------------------------------------------------------------------ +- +- lldb::addr_t +- AllocateMemory (size_t size, uint32_t permissions, Error &error); +- +- +- //------------------------------------------------------------------ +- /// Resolve dynamically loaded indirect functions. +- /// +- /// @param[in] address +- /// The load address of the indirect function to resolve. +- /// +- /// @param[out] error +- /// An error value in case the resolve fails. +- /// +- /// @return +- /// The address of the resolved function. +- /// LLDB_INVALID_ADDRESS if the resolution failed. +- //------------------------------------------------------------------ +- +- virtual lldb::addr_t +- ResolveIndirectFunction(const Address *address, Error &error) +- { +- error.SetErrorStringWithFormat("error: %s does not support indirect functions in the debug process", GetPluginName().GetCString()); +- return LLDB_INVALID_ADDRESS; +- } +- +- virtual Error +- GetMemoryRegionInfo (lldb::addr_t load_addr, +- MemoryRegionInfo &range_info) +- { +- Error error; +- error.SetErrorString ("Process::GetMemoryRegionInfo() not supported"); +- return error; +- } +- +- virtual Error +- GetWatchpointSupportInfo (uint32_t &num) +- { +- Error error; +- num = 0; +- error.SetErrorString ("Process::GetWatchpointSupportInfo() not supported"); +- return error; +- } +- +- virtual Error +- GetWatchpointSupportInfo (uint32_t &num, bool& after) +- { +- Error error; +- num = 0; +- after = true; +- error.SetErrorString ("Process::GetWatchpointSupportInfo() not supported"); +- return error; +- } +- +- lldb::ModuleSP +- ReadModuleFromMemory (const FileSpec& file_spec, +- lldb::addr_t header_addr); +- +- //------------------------------------------------------------------ +- /// Attempt to get the attributes for a region of memory in the process. +- /// +- /// It may be possible for the remote debug server to inspect attributes +- /// for a region of memory in the process, such as whether there is a +- /// valid page of memory at a given address or whether that page is +- /// readable/writable/executable by the process. +- /// +- /// @param[in] load_addr +- /// The address of interest in the process. +- /// +- /// @param[out] permissions +- /// If this call returns successfully, this bitmask will have +- /// its Permissions bits set to indicate whether the region is +- /// readable/writable/executable. If this call fails, the +- /// bitmask values are undefined. +- /// +- /// @return +- /// Returns true if it was able to determine the attributes of the +- /// memory region. False if not. +- //------------------------------------------------------------------ +- +- virtual bool +- GetLoadAddressPermissions (lldb::addr_t load_addr, uint32_t &permissions) +- { +- MemoryRegionInfo range_info; +- permissions = 0; +- Error error (GetMemoryRegionInfo (load_addr, range_info)); +- if (!error.Success()) +- return false; +- if (range_info.GetReadable() == MemoryRegionInfo::eDontKnow +- || range_info.GetWritable() == MemoryRegionInfo::eDontKnow +- || range_info.GetExecutable() == MemoryRegionInfo::eDontKnow) +- { +- return false; +- } +- +- if (range_info.GetReadable() == MemoryRegionInfo::eYes) +- permissions |= lldb::ePermissionsReadable; +- +- if (range_info.GetWritable() == MemoryRegionInfo::eYes) +- permissions |= lldb::ePermissionsWritable; +- +- if (range_info.GetExecutable() == MemoryRegionInfo::eYes) +- permissions |= lldb::ePermissionsExecutable; +- +- return true; +- } +- +- //------------------------------------------------------------------ +- /// Determines whether executing JIT-compiled code in this process +- /// is possible. +- /// +- /// @return +- /// True if execution of JIT code is possible; false otherwise. +- //------------------------------------------------------------------ +- bool CanJIT (); +- +- //------------------------------------------------------------------ +- /// Sets whether executing JIT-compiled code in this process +- /// is possible. +- /// +- /// @param[in] can_jit +- /// True if execution of JIT code is possible; false otherwise. +- //------------------------------------------------------------------ +- void SetCanJIT (bool can_jit); +- +- //------------------------------------------------------------------ +- /// Actually deallocate memory in the process. +- /// +- /// This function will deallocate memory in the process's address +- /// space that was allocated with AllocateMemory. +- /// +- /// @param[in] ptr +- /// A return value from AllocateMemory, pointing to the memory you +- /// want to deallocate. +- /// +- /// @return +- /// \btrue if the memory was deallocated, \bfalse otherwise. +- //------------------------------------------------------------------ +- +- virtual Error +- DoDeallocateMemory (lldb::addr_t ptr) +- { +- Error error; +- error.SetErrorStringWithFormat("error: %s does not support deallocating in the debug process", GetPluginName().GetCString()); +- return error; +- } +- +- +- //------------------------------------------------------------------ +- /// The public interface to deallocating memory in the process. +- /// +- /// This function will deallocate memory in the process's address +- /// space that was allocated with AllocateMemory. +- /// +- /// @param[in] ptr +- /// A return value from AllocateMemory, pointing to the memory you +- /// want to deallocate. +- /// +- /// @return +- /// \btrue if the memory was deallocated, \bfalse otherwise. +- //------------------------------------------------------------------ +- +- Error +- DeallocateMemory (lldb::addr_t ptr); +- +- //------------------------------------------------------------------ +- /// Get any available STDOUT. +- /// +- /// If the process was launched without supplying valid file paths +- /// for stdin, stdout, and stderr, then the Process class might +- /// try to cache the STDOUT for the process if it is able. Events +- /// will be queued indicating that there is STDOUT available that +- /// can be retrieved using this function. +- /// +- /// @param[out] buf +- /// A buffer that will receive any STDOUT bytes that are +- /// currently available. +- /// +- /// @param[out] buf_size +- /// The size in bytes for the buffer \a buf. +- /// +- /// @return +- /// The number of bytes written into \a buf. If this value is +- /// equal to \a buf_size, another call to this function should +- /// be made to retrieve more STDOUT data. +- //------------------------------------------------------------------ +- virtual size_t +- GetSTDOUT (char *buf, size_t buf_size, Error &error); +- +- //------------------------------------------------------------------ +- /// Get any available STDERR. +- /// +- /// If the process was launched without supplying valid file paths +- /// for stdin, stdout, and stderr, then the Process class might +- /// try to cache the STDERR for the process if it is able. Events +- /// will be queued indicating that there is STDERR available that +- /// can be retrieved using this function. +- /// +- /// @param[out] buf +- /// A buffer that will receive any STDERR bytes that are +- /// currently available. +- /// +- /// @param[out] buf_size +- /// The size in bytes for the buffer \a buf. +- /// +- /// @return +- /// The number of bytes written into \a buf. If this value is +- /// equal to \a buf_size, another call to this function should +- /// be made to retrieve more STDERR data. +- //------------------------------------------------------------------ +- virtual size_t +- GetSTDERR (char *buf, size_t buf_size, Error &error); +- +- virtual size_t +- PutSTDIN (const char *buf, size_t buf_size, Error &error) +- { +- error.SetErrorString("stdin unsupported"); +- return 0; +- } +- +- //------------------------------------------------------------------ +- /// Get any available profile data. +- /// +- /// @param[out] buf +- /// A buffer that will receive any profile data bytes that are +- /// currently available. +- /// +- /// @param[out] buf_size +- /// The size in bytes for the buffer \a buf. +- /// +- /// @return +- /// The number of bytes written into \a buf. If this value is +- /// equal to \a buf_size, another call to this function should +- /// be made to retrieve more profile data. +- //------------------------------------------------------------------ +- virtual size_t +- GetAsyncProfileData (char *buf, size_t buf_size, Error &error); +- +- //---------------------------------------------------------------------- +- // Process Breakpoints +- //---------------------------------------------------------------------- +- size_t +- GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site); +- +- virtual Error +- EnableBreakpointSite (BreakpointSite *bp_site) +- { +- Error error; +- error.SetErrorStringWithFormat("error: %s does not support enabling breakpoints", GetPluginName().GetCString()); +- return error; +- } +- +- +- virtual Error +- DisableBreakpointSite (BreakpointSite *bp_site) +- { +- Error error; +- error.SetErrorStringWithFormat("error: %s does not support disabling breakpoints", GetPluginName().GetCString()); +- return error; +- } +- +- +- // This is implemented completely using the lldb::Process API. Subclasses +- // don't need to implement this function unless the standard flow of +- // read existing opcode, write breakpoint opcode, verify breakpoint opcode +- // doesn't work for a specific process plug-in. +- virtual Error +- EnableSoftwareBreakpoint (BreakpointSite *bp_site); +- +- // This is implemented completely using the lldb::Process API. Subclasses +- // don't need to implement this function unless the standard flow of +- // restoring original opcode in memory and verifying the restored opcode +- // doesn't work for a specific process plug-in. +- virtual Error +- DisableSoftwareBreakpoint (BreakpointSite *bp_site); +- +- BreakpointSiteList & +- GetBreakpointSiteList(); +- +- const BreakpointSiteList & +- GetBreakpointSiteList() const; +- +- void +- DisableAllBreakpointSites (); +- +- Error +- ClearBreakpointSiteByID (lldb::user_id_t break_id); +- +- lldb::break_id_t +- CreateBreakpointSite (const lldb::BreakpointLocationSP &owner, +- bool use_hardware); +- +- Error +- DisableBreakpointSiteByID (lldb::user_id_t break_id); +- +- Error +- EnableBreakpointSiteByID (lldb::user_id_t break_id); +- +- +- // BreakpointLocations use RemoveOwnerFromBreakpointSite to remove +- // themselves from the owner's list of this breakpoint sites. +- void +- RemoveOwnerFromBreakpointSite (lldb::user_id_t owner_id, +- lldb::user_id_t owner_loc_id, +- lldb::BreakpointSiteSP &bp_site_sp); +- +- //---------------------------------------------------------------------- +- // Process Watchpoints (optional) +- //---------------------------------------------------------------------- +- virtual Error +- EnableWatchpoint (Watchpoint *wp, bool notify = true); +- +- virtual Error +- DisableWatchpoint (Watchpoint *wp, bool notify = true); +- +- //------------------------------------------------------------------ +- // Thread Queries +- //------------------------------------------------------------------ +- virtual bool +- UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list) = 0; +- +- void +- UpdateThreadListIfNeeded (); +- +- ThreadList & +- GetThreadList () +- { +- return m_thread_list; +- } +- +- // This is obsoleted and will be removed very soon. +- uint32_t +- GetNextThreadIndexID (); +- +- uint32_t +- GetNextThreadIndexID (uint64_t thread_id); +- +- lldb::ThreadSP +- CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context); +- +- // Returns true if an index id has been assigned to a thread. +- bool +- HasAssignedIndexIDToThread(uint64_t sb_thread_id); +- +- // Given a thread_id, it will assign a more reasonable index id for display to the user. +- // If the thread_id has previously been assigned, the same index id will be used. +- uint32_t +- AssignIndexIDToThread(uint64_t thread_id); +- +- //------------------------------------------------------------------ +- // Event Handling +- //------------------------------------------------------------------ +- lldb::StateType +- GetNextEvent (lldb::EventSP &event_sp); +- +- lldb::StateType +- WaitForProcessToStop (const TimeValue *timeout, lldb::EventSP *event_sp_ptr = NULL); +- +- lldb::StateType +- WaitForStateChangedEvents (const TimeValue *timeout, lldb::EventSP &event_sp); +- +- Event * +- PeekAtStateChangedEvents (); +- +- +- class +- ProcessEventHijacker +- { +- public: +- ProcessEventHijacker (Process &process, Listener *listener) : +- m_process (process) +- { +- m_process.HijackProcessEvents (listener); +- } +- ~ProcessEventHijacker () +- { +- m_process.RestoreProcessEvents(); +- } +- +- private: +- Process &m_process; +- }; +- friend class ProcessEventHijacker; +- //------------------------------------------------------------------ +- /// If you need to ensure that you and only you will hear about some public +- /// event, then make a new listener, set to listen to process events, and +- /// then call this with that listener. Then you will have to wait on that +- /// listener explicitly for events (rather than using the GetNextEvent & WaitFor* +- /// calls above. Be sure to call RestoreProcessEvents when you are done. +- /// +- /// @param[in] listener +- /// This is the new listener to whom all process events will be delivered. +- /// +- /// @return +- /// Returns \b true if the new listener could be installed, +- /// \b false otherwise. +- //------------------------------------------------------------------ +- bool +- HijackProcessEvents (Listener *listener); +- +- //------------------------------------------------------------------ +- /// Restores the process event broadcasting to its normal state. +- /// +- //------------------------------------------------------------------ +- void +- RestoreProcessEvents (); +- +-private: +- //------------------------------------------------------------------ +- /// This is the part of the event handling that for a process event. +- /// It decides what to do with the event and returns true if the +- /// event needs to be propagated to the user, and false otherwise. +- /// If the event is not propagated, this call will most likely set +- /// the target to executing again. +- /// There is only one place where this call should be called, HandlePrivateEvent. +- /// Don't call it from anywhere else... +- /// +- /// @param[in] event_ptr +- /// This is the event we are handling. +- /// +- /// @return +- /// Returns \b true if the event should be reported to the +- /// user, \b false otherwise. +- //------------------------------------------------------------------ +- bool +- ShouldBroadcastEvent (Event *event_ptr); +- +-public: +- const lldb::ABISP & +- GetABI (); +- +- OperatingSystem * +- GetOperatingSystem () +- { +- return m_os_ap.get(); +- } +- +- +- virtual LanguageRuntime * +- GetLanguageRuntime (lldb::LanguageType language, bool retry_if_null = true); +- +- virtual CPPLanguageRuntime * +- GetCPPLanguageRuntime (bool retry_if_null = true); +- +- virtual ObjCLanguageRuntime * +- GetObjCLanguageRuntime (bool retry_if_null = true); +- +- bool +- IsPossibleDynamicValue (ValueObject& in_value); +- +- bool +- IsRunning () const; +- +- DynamicCheckerFunctions *GetDynamicCheckers() +- { +- return m_dynamic_checkers_ap.get(); +- } +- +- void SetDynamicCheckers(DynamicCheckerFunctions *dynamic_checkers) +- { +- m_dynamic_checkers_ap.reset(dynamic_checkers); +- } +- +- //------------------------------------------------------------------ +- /// Call this to set the lldb in the mode where it breaks on new thread +- /// creations, and then auto-restarts. This is useful when you are trying +- /// to run only one thread, but either that thread or the kernel is creating +- /// new threads in the process. If you stop when the thread is created, you +- /// can immediately suspend it, and keep executing only the one thread you intend. +- /// +- /// @return +- /// Returns \b true if we were able to start up the notification +- /// \b false otherwise. +- //------------------------------------------------------------------ +- virtual bool +- StartNoticingNewThreads() +- { +- return true; +- } +- +- //------------------------------------------------------------------ +- /// Call this to turn off the stop & notice new threads mode. +- /// +- /// @return +- /// Returns \b true if we were able to start up the notification +- /// \b false otherwise. +- //------------------------------------------------------------------ +- virtual bool +- StopNoticingNewThreads() +- { +- return true; +- } +- +- void +- SetRunningUserExpression (bool on); +- +- //------------------------------------------------------------------ +- // lldb::ExecutionContextScope pure virtual functions +- //------------------------------------------------------------------ +- virtual lldb::TargetSP +- CalculateTarget (); +- +- virtual lldb::ProcessSP +- CalculateProcess () +- { +- return shared_from_this(); +- } +- +- virtual lldb::ThreadSP +- CalculateThread () +- { +- return lldb::ThreadSP(); +- } +- +- virtual lldb::StackFrameSP +- CalculateStackFrame () +- { +- return lldb::StackFrameSP(); +- } +- +- virtual void +- CalculateExecutionContext (ExecutionContext &exe_ctx); +- +- void +- SetSTDIOFileDescriptor (int file_descriptor); +- +- //------------------------------------------------------------------ +- // Add a permanent region of memory that should never be read or +- // written to. This can be used to ensure that memory reads or writes +- // to certain areas of memory never end up being sent to the +- // DoReadMemory or DoWriteMemory functions which can improve +- // performance. +- //------------------------------------------------------------------ +- void +- AddInvalidMemoryRegion (const LoadRange ®ion); +- +- //------------------------------------------------------------------ +- // Remove a permanent region of memory that should never be read or +- // written to that was previously added with AddInvalidMemoryRegion. +- //------------------------------------------------------------------ +- bool +- RemoveInvalidMemoryRange (const LoadRange ®ion); +- +- //------------------------------------------------------------------ +- // If the setup code of a thread plan needs to do work that might involve +- // calling a function in the target, it should not do that work directly +- // in one of the thread plan functions (DidPush/WillResume) because +- // such work needs to be handled carefully. Instead, put that work in +- // a PreResumeAction callback, and register it with the process. It will +- // get done before the actual "DoResume" gets called. +- //------------------------------------------------------------------ +- +- typedef bool (PreResumeActionCallback)(void *); +- +- void +- AddPreResumeAction (PreResumeActionCallback callback, void *baton); +- +- bool +- RunPreResumeActions (); +- +- void +- ClearPreResumeActions (); +- +- ReadWriteLock & +- GetRunLock () +- { +- // The "m_private_run_lock" causes problems for other platforms +- // right now, so we are leaving this in for Apple builds only +- // until we can get the kinks worked out. +- if (Host::GetCurrentThread() == m_private_state_thread) +- return m_private_run_lock; +- else +- return m_public_run_lock; +- } +- +- //------------------------------------------------------------------ +- // This is a cache of reserved and available memory address ranges +- // for a single modification ID (see m_mod_id). It's meant for use +- // by IRMemoryMap, but to stick with the process. These memory +- // ranges happen to be unallocated in the underlying process, but we +- // make no guarantee that at a future modification ID they won't be +- // gone. This is only useful if the underlying process can't +- // allocate memory. +- // +- // When a memory space is determined to be available it is +- // registered as reserved at the current modification. If it is +- // freed later, it is added to the free list if the modification ID +- // hasn't changed. Then clients can simply query the free list for +- // the size they want. +- //------------------------------------------------------------------ +- class ReservationCache +- { +- public: +- ReservationCache (Process &process); +- +- //------------------------------------------------------------------ +- // Mark that a particular range of addresses is in use. Adds it +- // to the reserved map, implicitly tying it to the current +- // modification ID. +- //------------------------------------------------------------------ +- void +- Reserve (lldb::addr_t addr, size_t size); +- +- //------------------------------------------------------------------ +- // Mark that a range is no longer in use. If it's found in the +- // reservation list, that means that the modification ID hasn't +- // changed since it was reserved, so it can be safely added to the +- // free list. +- //------------------------------------------------------------------ +- void +- Unreserve (lldb::addr_t addr); +- +- //------------------------------------------------------------------ +- // Try to find an unused range of the given size in the free list. +- //------------------------------------------------------------------ +- lldb::addr_t +- Find (size_t size); +- private: +- //------------------------------------------------------------------ +- // Clear all lists if the modification ID has changed. +- //------------------------------------------------------------------ +- void CheckModID(); +- +- typedef std::map ReservedMap; +- typedef std::vector FreeList; +- typedef std::map FreeMap; +- +- ReservedMap m_reserved_cache; +- FreeMap m_free_cache; +- +- Process &m_process; +- ProcessModID m_mod_id; +- }; +- +- ReservationCache & +- GetReservationCache () +- { +- return m_reservation_cache; +- } +-private: +- ReservationCache m_reservation_cache; +-protected: +- //------------------------------------------------------------------ +- // NextEventAction provides a way to register an action on the next +- // event that is delivered to this process. There is currently only +- // one next event action allowed in the process at one time. If a +- // new "NextEventAction" is added while one is already present, the +- // old action will be discarded (with HandleBeingUnshipped called +- // after it is discarded.) +- // +- // If you want to resume the process as a result of a resume action, +- // call RequestResume, don't call Resume directly. +- //------------------------------------------------------------------ +- class NextEventAction +- { +- public: +- typedef enum EventActionResult +- { +- eEventActionSuccess, +- eEventActionRetry, +- eEventActionExit +- } EventActionResult; +- +- NextEventAction (Process *process) : +- m_process(process) +- { +- } +- +- virtual +- ~NextEventAction() +- { +- } +- +- virtual EventActionResult PerformAction (lldb::EventSP &event_sp) = 0; +- virtual void HandleBeingUnshipped () {} +- virtual EventActionResult HandleBeingInterrupted () = 0; +- virtual const char *GetExitString() = 0; +- void RequestResume() +- { +- m_process->m_resume_requested = true; +- } +- protected: +- Process *m_process; +- }; +- +- void SetNextEventAction (Process::NextEventAction *next_event_action) +- { +- if (m_next_event_action_ap.get()) +- m_next_event_action_ap->HandleBeingUnshipped(); +- +- m_next_event_action_ap.reset(next_event_action); +- } +- +- // This is the completer for Attaching: +- class AttachCompletionHandler : public NextEventAction +- { +- public: +- AttachCompletionHandler (Process *process, uint32_t exec_count) : +- NextEventAction (process), +- m_exec_count (exec_count) +- { +- } +- +- virtual +- ~AttachCompletionHandler() +- { +- } +- +- virtual EventActionResult PerformAction (lldb::EventSP &event_sp); +- virtual EventActionResult HandleBeingInterrupted (); +- virtual const char *GetExitString(); +- private: +- uint32_t m_exec_count; +- std::string m_exit_string; +- }; +- +- bool +- HijackPrivateProcessEvents (Listener *listener); +- +- void +- RestorePrivateProcessEvents (); +- +- bool +- PrivateStateThreadIsValid () const +- { +- return IS_VALID_LLDB_HOST_THREAD(m_private_state_thread); +- } +- +- //------------------------------------------------------------------ +- // Type definitions +- //------------------------------------------------------------------ +- typedef std::map LanguageRuntimeCollection; +- +- struct PreResumeCallbackAndBaton +- { +- bool (*callback) (void *); +- void *baton; +- PreResumeCallbackAndBaton (PreResumeActionCallback in_callback, void *in_baton) : +- callback (in_callback), +- baton (in_baton) +- { +- } +- }; +- +- //------------------------------------------------------------------ +- // Member variables +- //------------------------------------------------------------------ +- Target & m_target; ///< The target that owns this process. +- ThreadSafeValue m_public_state; +- ThreadSafeValue m_private_state; // The actual state of our process +- Broadcaster m_private_state_broadcaster; // This broadcaster feeds state changed events into the private state thread's listener. +- Broadcaster m_private_state_control_broadcaster; // This is the control broadcaster, used to pause, resume & stop the private state thread. +- Listener m_private_state_listener; // This is the listener for the private state thread. +- Predicate m_private_state_control_wait; /// This Predicate is used to signal that a control operation is complete. +- lldb::thread_t m_private_state_thread; // Thread ID for the thread that watches interal state events +- ProcessModID m_mod_id; ///< Tracks the state of the process over stops and other alterations. +- uint32_t m_process_unique_id; ///< Each lldb_private::Process class that is created gets a unique integer ID that increments with each new instance +- uint32_t m_thread_index_id; ///< Each thread is created with a 1 based index that won't get re-used. +- std::map m_thread_id_to_index_id_map; +- int m_exit_status; ///< The exit status of the process, or -1 if not set. +- std::string m_exit_string; ///< A textual description of why a process exited. +- Mutex m_thread_mutex; +- ThreadList m_thread_list_real; ///< The threads for this process as are known to the protocol we are debugging with +- ThreadList m_thread_list; ///< The threads for this process as the user will see them. This is usually the same as +- ///< m_thread_list_real, but might be different if there is an OS plug-in creating memory threads +- std::vector m_notifications; ///< The list of notifications that this process can deliver. +- std::vector m_image_tokens; +- Listener &m_listener; +- BreakpointSiteList m_breakpoint_site_list; ///< This is the list of breakpoint locations we intend to insert in the target. +- std::unique_ptr m_dyld_ap; +- std::unique_ptr m_dynamic_checkers_ap; ///< The functions used by the expression parser to validate data that expressions use. +- std::unique_ptr m_os_ap; +- UnixSignals m_unix_signals; /// This is the current signal set for this process. +- lldb::ABISP m_abi_sp; +- lldb::InputReaderSP m_process_input_reader; +- Communication m_stdio_communication; +- Mutex m_stdio_communication_mutex; +- std::string m_stdout_data; +- std::string m_stderr_data; +- Mutex m_profile_data_comm_mutex; +- std::vector m_profile_data; +- MemoryCache m_memory_cache; +- AllocatedMemoryCache m_allocated_memory_cache; +- bool m_should_detach; /// Should we detach if the process object goes away with an explicit call to Kill or Detach? +- LanguageRuntimeCollection m_language_runtimes; +- std::unique_ptr m_next_event_action_ap; +- std::vector m_pre_resume_actions; +- ReadWriteLock m_public_run_lock; +- ReadWriteLock m_private_run_lock; +- Predicate m_currently_handling_event; // This predicate is set in HandlePrivateEvent while all its business is being done. +- bool m_currently_handling_do_on_removals; +- bool m_resume_requested; // If m_currently_handling_event or m_currently_handling_do_on_removals are true, Resume will only request a resume, using this flag to check. +- bool m_finalize_called; +- bool m_clear_thread_plans_on_stop; +- lldb::StateType m_last_broadcast_state; /// This helps with the Public event coalescing in ShouldBroadcastEvent. +- bool m_destroy_in_process; +- +- enum { +- eCanJITDontKnow= 0, +- eCanJITYes, +- eCanJITNo +- } m_can_jit; +- +- size_t +- RemoveBreakpointOpcodesFromBuffer (lldb::addr_t addr, size_t size, uint8_t *buf) const; +- +- void +- SynchronouslyNotifyStateChanged (lldb::StateType state); +- +- void +- SetPublicState (lldb::StateType new_state, bool restarted); +- +- void +- SetPrivateState (lldb::StateType state); +- +- bool +- StartPrivateStateThread (bool force = false); +- +- void +- StopPrivateStateThread (); +- +- void +- PausePrivateStateThread (); +- +- void +- ResumePrivateStateThread (); +- +- static void * +- PrivateStateThread (void *arg); +- +- void * +- RunPrivateStateThread (); +- +- void +- HandlePrivateEvent (lldb::EventSP &event_sp); +- +- lldb::StateType +- WaitForProcessStopPrivate (const TimeValue *timeout, lldb::EventSP &event_sp); +- +- // This waits for both the state change broadcaster, and the control broadcaster. +- // If control_only, it only waits for the control broadcaster. +- +- bool +- WaitForEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp, bool control_only); +- +- lldb::StateType +- WaitForStateChangedEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp); +- +- lldb::StateType +- WaitForState (const TimeValue *timeout, +- const lldb::StateType *match_states, +- const uint32_t num_match_states); +- +- size_t +- WriteMemoryPrivate (lldb::addr_t addr, const void *buf, size_t size, Error &error); +- +- void +- AppendSTDOUT (const char *s, size_t len); +- +- void +- AppendSTDERR (const char *s, size_t len); +- +- void +- BroadcastAsyncProfileData(const char *s, size_t len); +- +- static void +- STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len); +- +- void +- PushProcessInputReader (); +- +- void +- PopProcessInputReader (); +- +- void +- ResetProcessInputReader (); +- +- static size_t +- ProcessInputReaderCallback (void *baton, +- InputReader &reader, +- lldb::InputReaderAction notification, +- const char *bytes, +- size_t bytes_len); +- +- Error +- HaltForDestroyOrDetach(lldb::EventSP &exit_event_sp); +- +-private: +- //------------------------------------------------------------------ +- // For Process only +- //------------------------------------------------------------------ +- void ControlPrivateStateThread (uint32_t signal); +- +- DISALLOW_COPY_AND_ASSIGN (Process); +- +-}; +- +-} // namespace lldb_private +- +-#endif // liblldb_Process_h_ diff --git a/debian/patches/lldb-hurd.diff b/debian/patches/lldb-hurd.diff index e5d2d262..2841f193 100644 --- a/debian/patches/lldb-hurd.diff +++ b/debian/patches/lldb-hurd.diff @@ -11,6 +11,1526 @@ Index: llvm-toolchain-3.3-3.3/lldb/include/lldb/Host/Config.h #include "lldb/Host/linux/Config.h" +Index: llvm-toolchain-3.3-3.3/home/sylvestre/llvm-toolchain-3.3-3.3/tools/lldb/source/Host/common/Host.cpp +=================================================================== +--- llvm-toolchain-3.3-3.3.orig/home/sylvestre/llvm-toolchain-3.3-3.3/tools/lldb/source/Host/common/Host.cpp 2013-08-28 10:29:30.000000000 +0000 ++++ /dev/null 1970-01-01 00:00:00.000000000 +0000 +@@ -1,1515 +0,0 @@ +-//===-- Host.cpp ------------------------------------------------*- C++ -*-===// +-// +-// The LLVM Compiler Infrastructure +-// +-// This file is distributed under the University of Illinois Open Source +-// License. See LICENSE.TXT for details. +-// +-//===----------------------------------------------------------------------===// +- +-#include "lldb/lldb-python.h" +- +-// C includes +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +- +-#if defined (__APPLE__) +- +-#include +-#include +-#include +-#include +- +-#elif defined (__linux__) || defined(__FreeBSD_kernel__) +-/* Linux or the FreeBSD kernel with glibc (Debian KFreeBSD for example) */ +- +-#include +- +-#elif defined (__FreeBSD__) +- +-#include +-#include +- +-#endif +- +-#include "lldb/Host/Host.h" +-#include "lldb/Core/ArchSpec.h" +-#include "lldb/Core/ConstString.h" +-#include "lldb/Core/Debugger.h" +-#include "lldb/Core/Error.h" +-#include "lldb/Core/Log.h" +-#include "lldb/Core/StreamString.h" +-#include "lldb/Core/ThreadSafeSTLMap.h" +-#include "lldb/Host/Config.h" +-#include "lldb/Host/Endian.h" +-#include "lldb/Host/FileSpec.h" +-#include "lldb/Host/Mutex.h" +-#include "lldb/Target/Process.h" +-#include "lldb/Target/TargetList.h" +- +-#include "llvm/Support/Host.h" +-#include "llvm/Support/MachO.h" +-#include "llvm/ADT/Twine.h" +- +- +- +- +- +-using namespace lldb; +-using namespace lldb_private; +- +- +-#if !defined (__APPLE__) +-struct MonitorInfo +-{ +- lldb::pid_t pid; // The process ID to monitor +- Host::MonitorChildProcessCallback callback; // The callback function to call when "pid" exits or signals +- void *callback_baton; // The callback baton for the callback function +- bool monitor_signals; // If true, call the callback when "pid" gets signaled. +-}; +- +-static void * +-MonitorChildProcessThreadFunction (void *arg); +- +-lldb::thread_t +-Host::StartMonitoringChildProcess +-( +- Host::MonitorChildProcessCallback callback, +- void *callback_baton, +- lldb::pid_t pid, +- bool monitor_signals +-) +-{ +- lldb::thread_t thread = LLDB_INVALID_HOST_THREAD; +- MonitorInfo * info_ptr = new MonitorInfo(); +- +- info_ptr->pid = pid; +- info_ptr->callback = callback; +- info_ptr->callback_baton = callback_baton; +- info_ptr->monitor_signals = monitor_signals; +- +- char thread_name[256]; +- ::snprintf (thread_name, sizeof(thread_name), "", pid); +- thread = ThreadCreate (thread_name, +- MonitorChildProcessThreadFunction, +- info_ptr, +- NULL); +- +- return thread; +-} +- +-//------------------------------------------------------------------ +-// Scoped class that will disable thread canceling when it is +-// constructed, and exception safely restore the previous value it +-// when it goes out of scope. +-//------------------------------------------------------------------ +-class ScopedPThreadCancelDisabler +-{ +-public: +- ScopedPThreadCancelDisabler() +- { +- // Disable the ability for this thread to be cancelled +- int err = ::pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &m_old_state); +- if (err != 0) +- m_old_state = -1; +- +- } +- +- ~ScopedPThreadCancelDisabler() +- { +- // Restore the ability for this thread to be cancelled to what it +- // previously was. +- if (m_old_state != -1) +- ::pthread_setcancelstate (m_old_state, 0); +- } +-private: +- int m_old_state; // Save the old cancelability state. +-}; +- +-static void * +-MonitorChildProcessThreadFunction (void *arg) +-{ +- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); +- const char *function = __FUNCTION__; +- if (log) +- log->Printf ("%s (arg = %p) thread starting...", function, arg); +- +- MonitorInfo *info = (MonitorInfo *)arg; +- +- const Host::MonitorChildProcessCallback callback = info->callback; +- void * const callback_baton = info->callback_baton; +- const lldb::pid_t pid = info->pid; +- const bool monitor_signals = info->monitor_signals; +- +- delete info; +- +- int status = -1; +-#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) +- #define __WALL 0 +-#endif +- const int options = __WALL; +- +- while (1) +- { +- log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS); +- if (log) +- log->Printf("%s ::wait_pid (pid = %" PRIu64 ", &status, options = %i)...", function, pid, options); +- +- // Wait for all child processes +- ::pthread_testcancel (); +- // Get signals from all children with same process group of pid +- const lldb::pid_t wait_pid = ::waitpid (-1*pid, &status, options); +- ::pthread_testcancel (); +- +- if (wait_pid == -1) +- { +- if (errno == EINTR) +- continue; +- else +- { +- if (log) +- log->Printf ("%s (arg = %p) thread exiting because waitpid failed (%s)...", __FUNCTION__, arg, strerror(errno)); +- break; +- } +- } +- else if (wait_pid > 0) +- { +- bool exited = false; +- int signal = 0; +- int exit_status = 0; +- const char *status_cstr = NULL; +- if (WIFSTOPPED(status)) +- { +- signal = WSTOPSIG(status); +- status_cstr = "STOPPED"; +- } +- else if (WIFEXITED(status)) +- { +- exit_status = WEXITSTATUS(status); +- status_cstr = "EXITED"; +- exited = true; +- } +- else if (WIFSIGNALED(status)) +- { +- signal = WTERMSIG(status); +- status_cstr = "SIGNALED"; +- if (wait_pid == pid) { +- exited = true; +- exit_status = -1; +- } +- } +- else +- { +- status_cstr = "(\?\?\?)"; +- } +- +- // Scope for pthread_cancel_disabler +- { +- ScopedPThreadCancelDisabler pthread_cancel_disabler; +- +- log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS); +- if (log) +- log->Printf ("%s ::waitpid (pid = %" PRIu64 ", &status, options = %i) => pid = %" PRIu64 ", status = 0x%8.8x (%s), signal = %i, exit_state = %i", +- function, +- wait_pid, +- options, +- pid, +- status, +- status_cstr, +- signal, +- exit_status); +- +- if (exited || (signal != 0 && monitor_signals)) +- { +- bool callback_return = false; +- if (callback) +- callback_return = callback (callback_baton, wait_pid, exited, signal, exit_status); +- +- // If our process exited, then this thread should exit +- if (exited && wait_pid == pid) +- { +- if (log) +- log->Printf ("%s (arg = %p) thread exiting because pid received exit signal...", __FUNCTION__, arg); +- break; +- } +- // If the callback returns true, it means this process should +- // exit +- if (callback_return) +- { +- if (log) +- log->Printf ("%s (arg = %p) thread exiting because callback returned true...", __FUNCTION__, arg); +- break; +- } +- } +- } +- } +- } +- +- log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS); +- if (log) +- log->Printf ("%s (arg = %p) thread exiting...", __FUNCTION__, arg); +- +- return NULL; +-} +- +- +-void +-Host::SystemLog (SystemLogType type, const char *format, va_list args) +-{ +- vfprintf (stderr, format, args); +-} +- +-#endif // #if !defined (__APPLE__) +- +-void +-Host::SystemLog (SystemLogType type, const char *format, ...) +-{ +- va_list args; +- va_start (args, format); +- SystemLog (type, format, args); +- va_end (args); +-} +- +-size_t +-Host::GetPageSize() +-{ +- return ::getpagesize(); +-} +- +-const ArchSpec & +-Host::GetArchitecture (SystemDefaultArchitecture arch_kind) +-{ +- static bool g_supports_32 = false; +- static bool g_supports_64 = false; +- static ArchSpec g_host_arch_32; +- static ArchSpec g_host_arch_64; +- +-#if defined (__APPLE__) +- +- // Apple is different in that it can support both 32 and 64 bit executables +- // in the same operating system running concurrently. Here we detect the +- // correct host architectures for both 32 and 64 bit including if 64 bit +- // executables are supported on the system. +- +- if (g_supports_32 == false && g_supports_64 == false) +- { +- // All apple systems support 32 bit execution. +- g_supports_32 = true; +- uint32_t cputype, cpusubtype; +- uint32_t is_64_bit_capable = false; +- size_t len = sizeof(cputype); +- ArchSpec host_arch; +- // These will tell us about the kernel architecture, which even on a 64 +- // bit machine can be 32 bit... +- if (::sysctlbyname("hw.cputype", &cputype, &len, NULL, 0) == 0) +- { +- len = sizeof (cpusubtype); +- if (::sysctlbyname("hw.cpusubtype", &cpusubtype, &len, NULL, 0) != 0) +- cpusubtype = CPU_TYPE_ANY; +- +- len = sizeof (is_64_bit_capable); +- if (::sysctlbyname("hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0) == 0) +- { +- if (is_64_bit_capable) +- g_supports_64 = true; +- } +- +- if (is_64_bit_capable) +- { +-#if defined (__i386__) || defined (__x86_64__) +- if (cpusubtype == CPU_SUBTYPE_486) +- cpusubtype = CPU_SUBTYPE_I386_ALL; +-#endif +- if (cputype & CPU_ARCH_ABI64) +- { +- // We have a 64 bit kernel on a 64 bit system +- g_host_arch_32.SetArchitecture (eArchTypeMachO, ~(CPU_ARCH_MASK) & cputype, cpusubtype); +- g_host_arch_64.SetArchitecture (eArchTypeMachO, cputype, cpusubtype); +- } +- else +- { +- // We have a 32 bit kernel on a 64 bit system +- g_host_arch_32.SetArchitecture (eArchTypeMachO, cputype, cpusubtype); +- cputype |= CPU_ARCH_ABI64; +- g_host_arch_64.SetArchitecture (eArchTypeMachO, cputype, cpusubtype); +- } +- } +- else +- { +- g_host_arch_32.SetArchitecture (eArchTypeMachO, cputype, cpusubtype); +- g_host_arch_64.Clear(); +- } +- } +- } +- +-#else // #if defined (__APPLE__) +- +- if (g_supports_32 == false && g_supports_64 == false) +- { +- llvm::Triple triple(llvm::sys::getDefaultTargetTriple()); +- +- g_host_arch_32.Clear(); +- g_host_arch_64.Clear(); +- +- // If the OS is Linux, "unknown" in the vendor slot isn't what we want +- // for the default triple. It's probably an artifact of config.guess. +- if (triple.getOS() == llvm::Triple::Linux && triple.getVendor() == llvm::Triple::UnknownVendor) +- triple.setVendorName(""); +- +- switch (triple.getArch()) +- { +- default: +- g_host_arch_32.SetTriple(triple); +- g_supports_32 = true; +- break; +- +- case llvm::Triple::x86_64: +- g_host_arch_64.SetTriple(triple); +- g_supports_64 = true; +- g_host_arch_32.SetTriple(triple.get32BitArchVariant()); +- g_supports_32 = true; +- break; +- +- case llvm::Triple::sparcv9: +- case llvm::Triple::ppc64: +- g_host_arch_64.SetTriple(triple); +- g_supports_64 = true; +- break; +- } +- +- g_supports_32 = g_host_arch_32.IsValid(); +- g_supports_64 = g_host_arch_64.IsValid(); +- } +- +-#endif // #else for #if defined (__APPLE__) +- +- if (arch_kind == eSystemDefaultArchitecture32) +- return g_host_arch_32; +- else if (arch_kind == eSystemDefaultArchitecture64) +- return g_host_arch_64; +- +- if (g_supports_64) +- return g_host_arch_64; +- +- return g_host_arch_32; +-} +- +-const ConstString & +-Host::GetVendorString() +-{ +- static ConstString g_vendor; +- if (!g_vendor) +- { +- const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture); +- const llvm::StringRef &str_ref = host_arch.GetTriple().getVendorName(); +- g_vendor.SetCStringWithLength(str_ref.data(), str_ref.size()); +- } +- return g_vendor; +-} +- +-const ConstString & +-Host::GetOSString() +-{ +- static ConstString g_os_string; +- if (!g_os_string) +- { +- const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture); +- const llvm::StringRef &str_ref = host_arch.GetTriple().getOSName(); +- g_os_string.SetCStringWithLength(str_ref.data(), str_ref.size()); +- } +- return g_os_string; +-} +- +-const ConstString & +-Host::GetTargetTriple() +-{ +- static ConstString g_host_triple; +- if (!(g_host_triple)) +- { +- const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture); +- g_host_triple.SetCString(host_arch.GetTriple().getTriple().c_str()); +- } +- return g_host_triple; +-} +- +-lldb::pid_t +-Host::GetCurrentProcessID() +-{ +- return ::getpid(); +-} +- +-lldb::tid_t +-Host::GetCurrentThreadID() +-{ +-#if defined (__APPLE__) +- // Calling "mach_port_deallocate()" bumps the reference count on the thread +- // port, so we need to deallocate it. mach_task_self() doesn't bump the ref +- // count. +- thread_port_t thread_self = mach_thread_self(); +- mach_port_deallocate(mach_task_self(), thread_self); +- return thread_self; +-#elif defined(__FreeBSD__) +- return lldb::tid_t(pthread_getthreadid_np()); +-#else +- return lldb::tid_t(pthread_self()); +-#endif +-} +- +-lldb::thread_t +-Host::GetCurrentThread () +-{ +- return lldb::thread_t(pthread_self()); +-} +- +-const char * +-Host::GetSignalAsCString (int signo) +-{ +- switch (signo) +- { +- case SIGHUP: return "SIGHUP"; // 1 hangup +- case SIGINT: return "SIGINT"; // 2 interrupt +- case SIGQUIT: return "SIGQUIT"; // 3 quit +- case SIGILL: return "SIGILL"; // 4 illegal instruction (not reset when caught) +- case SIGTRAP: return "SIGTRAP"; // 5 trace trap (not reset when caught) +- case SIGABRT: return "SIGABRT"; // 6 abort() +-#if (defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE)) +- case SIGPOLL: return "SIGPOLL"; // 7 pollable event ([XSR] generated, not supported) +-#endif +-#if !defined(_POSIX_C_SOURCE) +- case SIGEMT: return "SIGEMT"; // 7 EMT instruction +-#endif +- case SIGFPE: return "SIGFPE"; // 8 floating point exception +- case SIGKILL: return "SIGKILL"; // 9 kill (cannot be caught or ignored) +- case SIGBUS: return "SIGBUS"; // 10 bus error +- case SIGSEGV: return "SIGSEGV"; // 11 segmentation violation +- case SIGSYS: return "SIGSYS"; // 12 bad argument to system call +- case SIGPIPE: return "SIGPIPE"; // 13 write on a pipe with no one to read it +- case SIGALRM: return "SIGALRM"; // 14 alarm clock +- case SIGTERM: return "SIGTERM"; // 15 software termination signal from kill +- case SIGURG: return "SIGURG"; // 16 urgent condition on IO channel +- case SIGSTOP: return "SIGSTOP"; // 17 sendable stop signal not from tty +- case SIGTSTP: return "SIGTSTP"; // 18 stop signal from tty +- case SIGCONT: return "SIGCONT"; // 19 continue a stopped process +- case SIGCHLD: return "SIGCHLD"; // 20 to parent on child stop or exit +- case SIGTTIN: return "SIGTTIN"; // 21 to readers pgrp upon background tty read +- case SIGTTOU: return "SIGTTOU"; // 22 like TTIN for output if (tp->t_local<OSTOP) +-#if !defined(_POSIX_C_SOURCE) +- case SIGIO: return "SIGIO"; // 23 input/output possible signal +-#endif +- case SIGXCPU: return "SIGXCPU"; // 24 exceeded CPU time limit +- case SIGXFSZ: return "SIGXFSZ"; // 25 exceeded file size limit +- case SIGVTALRM: return "SIGVTALRM"; // 26 virtual time alarm +- case SIGPROF: return "SIGPROF"; // 27 profiling time alarm +-#if !defined(_POSIX_C_SOURCE) +- case SIGWINCH: return "SIGWINCH"; // 28 window size changes +- case SIGINFO: return "SIGINFO"; // 29 information request +-#endif +- case SIGUSR1: return "SIGUSR1"; // 30 user defined signal 1 +- case SIGUSR2: return "SIGUSR2"; // 31 user defined signal 2 +- default: +- break; +- } +- return NULL; +-} +- +-void +-Host::WillTerminate () +-{ +-} +- +-#if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__linux__) && !defined(__FreeBSD_kernel__) // see macosx/Host.mm +- +- +-void +-Host::ThreadCreated (const char *thread_name) +-{ +-} +- +-void +-Host::Backtrace (Stream &strm, uint32_t max_frames) +-{ +- // TODO: Is there a way to backtrace the current process on linux? Other systems? +-} +- +-size_t +-Host::GetEnvironment (StringList &env) +-{ +- // TODO: Is there a way to the host environment for this process on linux? Other systems? +- return 0; +-} +- +-#endif // #if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__linux__) +- +-struct HostThreadCreateInfo +-{ +- std::string thread_name; +- thread_func_t thread_fptr; +- thread_arg_t thread_arg; +- +- HostThreadCreateInfo (const char *name, thread_func_t fptr, thread_arg_t arg) : +- thread_name (name ? name : ""), +- thread_fptr (fptr), +- thread_arg (arg) +- { +- } +-}; +- +-static thread_result_t +-ThreadCreateTrampoline (thread_arg_t arg) +-{ +- HostThreadCreateInfo *info = (HostThreadCreateInfo *)arg; +- Host::ThreadCreated (info->thread_name.c_str()); +- thread_func_t thread_fptr = info->thread_fptr; +- thread_arg_t thread_arg = info->thread_arg; +- +- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD)); +- if (log) +- log->Printf("thread created"); +- +- delete info; +- return thread_fptr (thread_arg); +-} +- +-lldb::thread_t +-Host::ThreadCreate +-( +- const char *thread_name, +- thread_func_t thread_fptr, +- thread_arg_t thread_arg, +- Error *error +-) +-{ +- lldb::thread_t thread = LLDB_INVALID_HOST_THREAD; +- +- // Host::ThreadCreateTrampoline will delete this pointer for us. +- HostThreadCreateInfo *info_ptr = new HostThreadCreateInfo (thread_name, thread_fptr, thread_arg); +- +- int err = ::pthread_create (&thread, NULL, ThreadCreateTrampoline, info_ptr); +- if (err == 0) +- { +- if (error) +- error->Clear(); +- return thread; +- } +- +- if (error) +- error->SetError (err, eErrorTypePOSIX); +- +- return LLDB_INVALID_HOST_THREAD; +-} +- +-bool +-Host::ThreadCancel (lldb::thread_t thread, Error *error) +-{ +- int err = ::pthread_cancel (thread); +- if (error) +- error->SetError(err, eErrorTypePOSIX); +- return err == 0; +-} +- +-bool +-Host::ThreadDetach (lldb::thread_t thread, Error *error) +-{ +- int err = ::pthread_detach (thread); +- if (error) +- error->SetError(err, eErrorTypePOSIX); +- return err == 0; +-} +- +-bool +-Host::ThreadJoin (lldb::thread_t thread, thread_result_t *thread_result_ptr, Error *error) +-{ +- int err = ::pthread_join (thread, thread_result_ptr); +- if (error) +- error->SetError(err, eErrorTypePOSIX); +- return err == 0; +-} +- +- +-std::string +-Host::GetThreadName (lldb::pid_t pid, lldb::tid_t tid) +-{ +- std::string thread_name; +-#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 +- // We currently can only get the name of a thread in the current process. +- if (pid == Host::GetCurrentProcessID()) +- { +- char pthread_name[1024]; +- if (::pthread_getname_np (::pthread_from_mach_thread_np (tid), pthread_name, sizeof(pthread_name)) == 0) +- { +- if (pthread_name[0]) +- { +- thread_name = pthread_name; +- } +- } +- else +- { +- dispatch_queue_t current_queue = ::dispatch_get_current_queue (); +- if (current_queue != NULL) +- { +- const char *queue_name = dispatch_queue_get_label (current_queue); +- if (queue_name && queue_name[0]) +- { +- thread_name = queue_name; +- } +- } +- } +- } +-#endif +- return thread_name; +-} +- +-bool +-Host::SetThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name) +-{ +-#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 +- lldb::pid_t curr_pid = Host::GetCurrentProcessID(); +- lldb::tid_t curr_tid = Host::GetCurrentThreadID(); +- if (pid == LLDB_INVALID_PROCESS_ID) +- pid = curr_pid; +- +- if (tid == LLDB_INVALID_THREAD_ID) +- tid = curr_tid; +- +- // Set the pthread name if possible +- if (pid == curr_pid && tid == curr_tid) +- { +- if (::pthread_setname_np (name) == 0) +- return true; +- } +- return false; +-#elif defined (__linux__) +- void *fn = dlsym (RTLD_DEFAULT, "pthread_setname_np"); +- if (fn) +- { +- int (*pthread_setname_np_func)(pthread_t thread, const char *name); +- *reinterpret_cast (&pthread_setname_np_func) = fn; +- +- lldb::pid_t curr_pid = Host::GetCurrentProcessID(); +- lldb::tid_t curr_tid = Host::GetCurrentThreadID(); +- +- if (pid == LLDB_INVALID_PROCESS_ID) +- pid = curr_pid; +- +- if (tid == LLDB_INVALID_THREAD_ID) +- tid = curr_tid; +- +- if (pid == curr_pid) +- { +- if (pthread_setname_np_func (tid, name) == 0) +- return true; +- } +- } +- return false; +-#else +- return false; +-#endif +-} +- +-FileSpec +-Host::GetProgramFileSpec () +-{ +- static FileSpec g_program_filespec; +- if (!g_program_filespec) +- { +-#if defined (__APPLE__) +- char program_fullpath[PATH_MAX]; +- // If DST is NULL, then return the number of bytes needed. +- uint32_t len = sizeof(program_fullpath); +- int err = _NSGetExecutablePath (program_fullpath, &len); +- if (err == 0) +- g_program_filespec.SetFile (program_fullpath, false); +- else if (err == -1) +- { +- char *large_program_fullpath = (char *)::malloc (len + 1); +- +- err = _NSGetExecutablePath (large_program_fullpath, &len); +- if (err == 0) +- g_program_filespec.SetFile (large_program_fullpath, false); +- +- ::free (large_program_fullpath); +- } +-#elif defined (__linux__) +- char exe_path[PATH_MAX]; +- ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1); +- if (len > 0) { +- exe_path[len] = 0; +- g_program_filespec.SetFile(exe_path, false); +- } +-#elif defined (__FreeBSD__) +- int exe_path_mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, getpid() }; +- size_t exe_path_size; +- if (sysctl(exe_path_mib, 4, NULL, &exe_path_size, NULL, 0) == 0) +- { +- char *exe_path = new char[exe_path_size]; +- if (sysctl(exe_path_mib, 4, exe_path, &exe_path_size, NULL, 0) == 0) +- g_program_filespec.SetFile(exe_path, false); +- delete[] exe_path; +- } +-#endif +- } +- return g_program_filespec; +-} +- +-FileSpec +-Host::GetModuleFileSpecForHostAddress (const void *host_addr) +-{ +- FileSpec module_filespec; +- Dl_info info; +- if (::dladdr (host_addr, &info)) +- { +- if (info.dli_fname) +- module_filespec.SetFile(info.dli_fname, true); +- } +- return module_filespec; +-} +- +-#if !defined (__APPLE__) // see Host.mm +- +-bool +-Host::GetBundleDirectory (const FileSpec &file, FileSpec &bundle) +-{ +- bundle.Clear(); +- return false; +-} +- +-bool +-Host::ResolveExecutableInBundle (FileSpec &file) +-{ +- return false; +-} +-#endif +- +-// Opaque info that tracks a dynamic library that was loaded +-struct DynamicLibraryInfo +-{ +- DynamicLibraryInfo (const FileSpec &fs, int o, void *h) : +- file_spec (fs), +- open_options (o), +- handle (h) +- { +- } +- +- const FileSpec file_spec; +- uint32_t open_options; +- void * handle; +-}; +- +-void * +-Host::DynamicLibraryOpen (const FileSpec &file_spec, uint32_t options, Error &error) +-{ +- char path[PATH_MAX]; +- if (file_spec.GetPath(path, sizeof(path))) +- { +- int mode = 0; +- +- if (options & eDynamicLibraryOpenOptionLazy) +- mode |= RTLD_LAZY; +- else +- mode |= RTLD_NOW; +- +- +- if (options & eDynamicLibraryOpenOptionLocal) +- mode |= RTLD_LOCAL; +- else +- mode |= RTLD_GLOBAL; +- +-#ifdef LLDB_CONFIG_DLOPEN_RTLD_FIRST_SUPPORTED +- if (options & eDynamicLibraryOpenOptionLimitGetSymbol) +- mode |= RTLD_FIRST; +-#endif +- +- void * opaque = ::dlopen (path, mode); +- +- if (opaque) +- { +- error.Clear(); +- return new DynamicLibraryInfo (file_spec, options, opaque); +- } +- else +- { +- error.SetErrorString(::dlerror()); +- } +- } +- else +- { +- error.SetErrorString("failed to extract path"); +- } +- return NULL; +-} +- +-Error +-Host::DynamicLibraryClose (void *opaque) +-{ +- Error error; +- if (opaque == NULL) +- { +- error.SetErrorString ("invalid dynamic library handle"); +- } +- else +- { +- DynamicLibraryInfo *dylib_info = (DynamicLibraryInfo *) opaque; +- if (::dlclose (dylib_info->handle) != 0) +- { +- error.SetErrorString(::dlerror()); +- } +- +- dylib_info->open_options = 0; +- dylib_info->handle = 0; +- delete dylib_info; +- } +- return error; +-} +- +-void * +-Host::DynamicLibraryGetSymbol (void *opaque, const char *symbol_name, Error &error) +-{ +- if (opaque == NULL) +- { +- error.SetErrorString ("invalid dynamic library handle"); +- } +- else +- { +- DynamicLibraryInfo *dylib_info = (DynamicLibraryInfo *) opaque; +- +- void *symbol_addr = ::dlsym (dylib_info->handle, symbol_name); +- if (symbol_addr) +- { +-#ifndef LLDB_CONFIG_DLOPEN_RTLD_FIRST_SUPPORTED +- // This host doesn't support limiting searches to this shared library +- // so we need to verify that the match came from this shared library +- // if it was requested in the Host::DynamicLibraryOpen() function. +- if (dylib_info->open_options & eDynamicLibraryOpenOptionLimitGetSymbol) +- { +- FileSpec match_dylib_spec (Host::GetModuleFileSpecForHostAddress (symbol_addr)); +- if (match_dylib_spec != dylib_info->file_spec) +- { +- char dylib_path[PATH_MAX]; +- if (dylib_info->file_spec.GetPath (dylib_path, sizeof(dylib_path))) +- error.SetErrorStringWithFormat ("symbol not found in \"%s\"", dylib_path); +- else +- error.SetErrorString ("symbol not found"); +- return NULL; +- } +- } +-#endif +- error.Clear(); +- return symbol_addr; +- } +- else +- { +- error.SetErrorString(::dlerror()); +- } +- } +- return NULL; +-} +- +-bool +-Host::GetLLDBPath (PathType path_type, FileSpec &file_spec) +-{ +- // To get paths related to LLDB we get the path to the executable that +- // contains this function. On MacOSX this will be "LLDB.framework/.../LLDB", +- // on linux this is assumed to be the "lldb" main executable. If LLDB on +- // linux is actually in a shared library (lldb.so??) then this function will +- // need to be modified to "do the right thing". +- +- switch (path_type) +- { +- case ePathTypeLLDBShlibDir: +- { +- static ConstString g_lldb_so_dir; +- if (!g_lldb_so_dir) +- { +- FileSpec lldb_file_spec (Host::GetModuleFileSpecForHostAddress ((void *)Host::GetLLDBPath)); +- g_lldb_so_dir = lldb_file_spec.GetDirectory(); +- } +- file_spec.GetDirectory() = g_lldb_so_dir; +- return file_spec.GetDirectory(); +- } +- break; +- +- case ePathTypeSupportExecutableDir: +- { +- static ConstString g_lldb_support_exe_dir; +- if (!g_lldb_support_exe_dir) +- { +- FileSpec lldb_file_spec; +- if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec)) +- { +- char raw_path[PATH_MAX]; +- char resolved_path[PATH_MAX]; +- lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); +- +-#if defined (__APPLE__) +- char *framework_pos = ::strstr (raw_path, "LLDB.framework"); +- if (framework_pos) +- { +- framework_pos += strlen("LLDB.framework"); +-#if !defined (__arm__) +- ::strncpy (framework_pos, "/Resources", PATH_MAX - (framework_pos - raw_path)); +-#endif +- } +-#endif +- FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path)); +- g_lldb_support_exe_dir.SetCString(resolved_path); +- } +- } +- file_spec.GetDirectory() = g_lldb_support_exe_dir; +- return file_spec.GetDirectory(); +- } +- break; +- +- case ePathTypeHeaderDir: +- { +- static ConstString g_lldb_headers_dir; +- if (!g_lldb_headers_dir) +- { +-#if defined (__APPLE__) +- FileSpec lldb_file_spec; +- if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec)) +- { +- char raw_path[PATH_MAX]; +- char resolved_path[PATH_MAX]; +- lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); +- +- char *framework_pos = ::strstr (raw_path, "LLDB.framework"); +- if (framework_pos) +- { +- framework_pos += strlen("LLDB.framework"); +- ::strncpy (framework_pos, "/Headers", PATH_MAX - (framework_pos - raw_path)); +- } +- FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path)); +- g_lldb_headers_dir.SetCString(resolved_path); +- } +-#else +- // TODO: Anyone know how we can determine this for linux? Other systems?? +- g_lldb_headers_dir.SetCString ("/opt/local/include/lldb"); +-#endif +- } +- file_spec.GetDirectory() = g_lldb_headers_dir; +- return file_spec.GetDirectory(); +- } +- break; +- +- case ePathTypePythonDir: +- { +- static ConstString g_lldb_python_dir; +- if (!g_lldb_python_dir) +- { +- FileSpec lldb_file_spec; +- if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec)) +- { +- char raw_path[PATH_MAX]; +- char resolved_path[PATH_MAX]; +- lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); +- +-#if defined (__APPLE__) +- char *framework_pos = ::strstr (raw_path, "LLDB.framework"); +- if (framework_pos) +- { +- framework_pos += strlen("LLDB.framework"); +- ::strncpy (framework_pos, "/Resources/Python", PATH_MAX - (framework_pos - raw_path)); +- } +-#else +- llvm::Twine python_version_dir; +- python_version_dir = "/python" +- + llvm::Twine(PY_MAJOR_VERSION) +- + "." +- + llvm::Twine(PY_MINOR_VERSION) +- + "/site-packages"; +- +- // We may get our string truncated. Should we protect +- // this with an assert? +- +- ::strncat(raw_path, python_version_dir.str().c_str(), +- sizeof(raw_path) - strlen(raw_path) - 1); +- +-#endif +- FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path)); +- g_lldb_python_dir.SetCString(resolved_path); +- } +- } +- file_spec.GetDirectory() = g_lldb_python_dir; +- return file_spec.GetDirectory(); +- } +- break; +- +- case ePathTypeLLDBSystemPlugins: // System plug-ins directory +- { +-#if defined (__APPLE__) +- static ConstString g_lldb_system_plugin_dir; +- static bool g_lldb_system_plugin_dir_located = false; +- if (!g_lldb_system_plugin_dir_located) +- { +- g_lldb_system_plugin_dir_located = true; +- FileSpec lldb_file_spec; +- if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec)) +- { +- char raw_path[PATH_MAX]; +- char resolved_path[PATH_MAX]; +- lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); +- +- char *framework_pos = ::strstr (raw_path, "LLDB.framework"); +- if (framework_pos) +- { +- framework_pos += strlen("LLDB.framework"); +- ::strncpy (framework_pos, "/Resources/PlugIns", PATH_MAX - (framework_pos - raw_path)); +- FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path)); +- g_lldb_system_plugin_dir.SetCString(resolved_path); +- } +- return false; +- } +- } +- +- if (g_lldb_system_plugin_dir) +- { +- file_spec.GetDirectory() = g_lldb_system_plugin_dir; +- return true; +- } +-#endif +- // TODO: where would system LLDB plug-ins be located on linux? Other systems? +- return false; +- } +- break; +- +- case ePathTypeLLDBUserPlugins: // User plug-ins directory +- { +-#if defined (__APPLE__) +- static ConstString g_lldb_user_plugin_dir; +- if (!g_lldb_user_plugin_dir) +- { +- char user_plugin_path[PATH_MAX]; +- if (FileSpec::Resolve ("~/Library/Application Support/LLDB/PlugIns", +- user_plugin_path, +- sizeof(user_plugin_path))) +- { +- g_lldb_user_plugin_dir.SetCString(user_plugin_path); +- } +- } +- file_spec.GetDirectory() = g_lldb_user_plugin_dir; +- return file_spec.GetDirectory(); +-#endif +- // TODO: where would user LLDB plug-ins be located on linux? Other systems? +- return false; +- } +- } +- +- return false; +-} +- +- +-bool +-Host::GetHostname (std::string &s) +-{ +- char hostname[PATH_MAX]; +- hostname[sizeof(hostname) - 1] = '\0'; +- if (::gethostname (hostname, sizeof(hostname) - 1) == 0) +- { +- struct hostent* h = ::gethostbyname (hostname); +- if (h) +- s.assign (h->h_name); +- else +- s.assign (hostname); +- return true; +- } +- return false; +-} +- +-const char * +-Host::GetUserName (uint32_t uid, std::string &user_name) +-{ +- struct passwd user_info; +- struct passwd *user_info_ptr = &user_info; +- char user_buffer[PATH_MAX]; +- size_t user_buffer_size = sizeof(user_buffer); +- if (::getpwuid_r (uid, +- &user_info, +- user_buffer, +- user_buffer_size, +- &user_info_ptr) == 0) +- { +- if (user_info_ptr) +- { +- user_name.assign (user_info_ptr->pw_name); +- return user_name.c_str(); +- } +- } +- user_name.clear(); +- return NULL; +-} +- +-const char * +-Host::GetGroupName (uint32_t gid, std::string &group_name) +-{ +- char group_buffer[PATH_MAX]; +- size_t group_buffer_size = sizeof(group_buffer); +- struct group group_info; +- struct group *group_info_ptr = &group_info; +- // Try the threadsafe version first +- if (::getgrgid_r (gid, +- &group_info, +- group_buffer, +- group_buffer_size, +- &group_info_ptr) == 0) +- { +- if (group_info_ptr) +- { +- group_name.assign (group_info_ptr->gr_name); +- return group_name.c_str(); +- } +- } +- else +- { +- // The threadsafe version isn't currently working +- // for me on darwin, but the non-threadsafe version +- // is, so I am calling it below. +- group_info_ptr = ::getgrgid (gid); +- if (group_info_ptr) +- { +- group_name.assign (group_info_ptr->gr_name); +- return group_name.c_str(); +- } +- } +- group_name.clear(); +- return NULL; +-} +- +-#if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined(__FreeBSD_kernel__) // see macosx/Host.mm +-bool +-Host::GetOSBuildString (std::string &s) +-{ +- s.clear(); +- return false; +-} +- +-bool +-Host::GetOSKernelDescription (std::string &s) +-{ +- s.clear(); +- return false; +-} +-#endif +- +-uint32_t +-Host::GetUserID () +-{ +- return getuid(); +-} +- +-uint32_t +-Host::GetGroupID () +-{ +- return getgid(); +-} +- +-uint32_t +-Host::GetEffectiveUserID () +-{ +- return geteuid(); +-} +- +-uint32_t +-Host::GetEffectiveGroupID () +-{ +- return getegid(); +-} +- +-#if !defined (__APPLE__) && !defined(__linux__) +-uint32_t +-Host::FindProcesses (const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos) +-{ +- process_infos.Clear(); +- return process_infos.GetSize(); +-} +-#endif // #if !defined (__APPLE__) && !defined(__linux__) +- +-#if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined(__linux__)&& !defined(__FreeBSD_kernel__) +-bool +-Host::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info) +-{ +- process_info.Clear(); +- return false; +-} +-#endif +- +-#if !defined(__linux__) +-bool +-Host::FindProcessThreads (const lldb::pid_t pid, TidMap &tids_to_attach) +-{ +- return false; +-} +-#endif +- +-lldb::TargetSP +-Host::GetDummyTarget (lldb_private::Debugger &debugger) +-{ +- static TargetSP g_dummy_target_sp; +- +- // FIXME: Maybe the dummy target should be per-Debugger +- if (!g_dummy_target_sp || !g_dummy_target_sp->IsValid()) +- { +- ArchSpec arch(Target::GetDefaultArchitecture()); +- if (!arch.IsValid()) +- arch = Host::GetArchitecture (); +- Error err = debugger.GetTargetList().CreateTarget(debugger, +- NULL, +- arch.GetTriple().getTriple().c_str(), +- false, +- NULL, +- g_dummy_target_sp); +- } +- +- return g_dummy_target_sp; +-} +- +-struct ShellInfo +-{ +- ShellInfo () : +- process_reaped (false), +- can_delete (false), +- pid (LLDB_INVALID_PROCESS_ID), +- signo(-1), +- status(-1) +- { +- } +- +- lldb_private::Predicate process_reaped; +- lldb_private::Predicate can_delete; +- lldb::pid_t pid; +- int signo; +- int status; +-}; +- +-static bool +-MonitorShellCommand (void *callback_baton, +- lldb::pid_t pid, +- bool exited, // True if the process did exit +- int signo, // Zero for no signal +- int status) // Exit value of process if signal is zero +-{ +- ShellInfo *shell_info = (ShellInfo *)callback_baton; +- shell_info->pid = pid; +- shell_info->signo = signo; +- shell_info->status = status; +- // Let the thread running Host::RunShellCommand() know that the process +- // exited and that ShellInfo has been filled in by broadcasting to it +- shell_info->process_reaped.SetValue(1, eBroadcastAlways); +- // Now wait for a handshake back from that thread running Host::RunShellCommand +- // so we know that we can delete shell_info_ptr +- shell_info->can_delete.WaitForValueEqualTo(true); +- // Sleep a bit to allow the shell_info->can_delete.SetValue() to complete... +- usleep(1000); +- // Now delete the shell info that was passed into this function +- delete shell_info; +- return true; +-} +- +-Error +-Host::RunShellCommand (const char *command, +- const char *working_dir, +- int *status_ptr, +- int *signo_ptr, +- std::string *command_output_ptr, +- uint32_t timeout_sec, +- const char *shell) +-{ +- Error error; +- ProcessLaunchInfo launch_info; +- if (shell && shell[0]) +- { +- // Run the command in a shell +- launch_info.SetShell(shell); +- launch_info.GetArguments().AppendArgument(command); +- const bool localhost = true; +- const bool will_debug = false; +- const bool first_arg_is_full_shell_command = true; +- launch_info.ConvertArgumentsForLaunchingInShell (error, +- localhost, +- will_debug, +- first_arg_is_full_shell_command); +- } +- else +- { +- // No shell, just run it +- Args args (command); +- const bool first_arg_is_executable = true; +- launch_info.SetArguments(args, first_arg_is_executable); +- } +- +- if (working_dir) +- launch_info.SetWorkingDirectory(working_dir); +- char output_file_path_buffer[L_tmpnam]; +- const char *output_file_path = NULL; +- if (command_output_ptr) +- { +- // Create a temporary file to get the stdout/stderr and redirect the +- // output of the command into this file. We will later read this file +- // if all goes well and fill the data into "command_output_ptr" +- output_file_path = ::tmpnam(output_file_path_buffer); +- launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false); +- launch_info.AppendOpenFileAction(STDOUT_FILENO, output_file_path, false, true); +- launch_info.AppendDuplicateFileAction(STDOUT_FILENO, STDERR_FILENO); +- } +- else +- { +- launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false); +- launch_info.AppendSuppressFileAction (STDOUT_FILENO, false, true); +- launch_info.AppendSuppressFileAction (STDERR_FILENO, false, true); +- } +- +- // The process monitor callback will delete the 'shell_info_ptr' below... +- std::unique_ptr shell_info_ap (new ShellInfo()); +- +- const bool monitor_signals = false; +- launch_info.SetMonitorProcessCallback(MonitorShellCommand, shell_info_ap.get(), monitor_signals); +- +- error = LaunchProcess (launch_info); +- const lldb::pid_t pid = launch_info.GetProcessID(); +- if (pid != LLDB_INVALID_PROCESS_ID) +- { +- // The process successfully launched, so we can defer ownership of +- // "shell_info" to the MonitorShellCommand callback function that will +- // get called when the process dies. We release the unique pointer as it +- // doesn't need to delete the ShellInfo anymore. +- ShellInfo *shell_info = shell_info_ap.release(); +- TimeValue timeout_time(TimeValue::Now()); +- timeout_time.OffsetWithSeconds(timeout_sec); +- bool timed_out = false; +- shell_info->process_reaped.WaitForValueEqualTo(true, &timeout_time, &timed_out); +- if (timed_out) +- { +- error.SetErrorString("timed out waiting for shell command to complete"); +- +- // Kill the process since it didn't complete withint the timeout specified +- ::kill (pid, SIGKILL); +- // Wait for the monitor callback to get the message +- timeout_time = TimeValue::Now(); +- timeout_time.OffsetWithSeconds(1); +- timed_out = false; +- shell_info->process_reaped.WaitForValueEqualTo(true, &timeout_time, &timed_out); +- } +- else +- { +- if (status_ptr) +- *status_ptr = shell_info->status; +- +- if (signo_ptr) +- *signo_ptr = shell_info->signo; +- +- if (command_output_ptr) +- { +- command_output_ptr->clear(); +- FileSpec file_spec(output_file_path, File::eOpenOptionRead); +- uint64_t file_size = file_spec.GetByteSize(); +- if (file_size > 0) +- { +- if (file_size > command_output_ptr->max_size()) +- { +- error.SetErrorStringWithFormat("shell command output is too large to fit into a std::string"); +- } +- else +- { +- command_output_ptr->resize(file_size); +- file_spec.ReadFileContents(0, &((*command_output_ptr)[0]), command_output_ptr->size(), &error); +- } +- } +- } +- } +- shell_info->can_delete.SetValue(true, eBroadcastAlways); +- } +- else +- { +- error.SetErrorString("failed to get process ID"); +- } +- +- if (output_file_path) +- ::unlink (output_file_path); +- // Handshake with the monitor thread, or just let it know in advance that +- // it can delete "shell_info" in case we timed out and were not able to kill +- // the process... +- return error; +-} +- +- +-uint32_t +-Host::GetNumberCPUS () +-{ +- static uint32_t g_num_cores = UINT32_MAX; +- if (g_num_cores == UINT32_MAX) +- { +-#if defined(__APPLE__) or defined (__linux__) or defined (__FreeBSD__) +- +- g_num_cores = ::sysconf(_SC_NPROCESSORS_ONLN); +- +-#elif defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +- +- // Header file for this might need to be included at the top of this file +- SYSTEM_INFO system_info; +- ::GetSystemInfo (&system_info); +- g_num_cores = system_info.dwNumberOfProcessors; +- +-#else +- +- // Assume POSIX support if a host specific case has not been supplied above +- g_num_cores = 0; +- int num_cores = 0; +- size_t num_cores_len = sizeof(num_cores); +-#ifdef HW_AVAILCPU +- int mib[] = { CTL_HW, HW_AVAILCPU }; +-#else +- int mib[] = { CTL_HW, HW_NCPU }; +-#endif +- +- /* get the number of CPUs from the system */ +- if (sysctl(mib, sizeof(mib)/sizeof(int), &num_cores, &num_cores_len, NULL, 0) == 0 && (num_cores > 0)) +- { +- g_num_cores = num_cores; +- } +- else +- { +- mib[1] = HW_NCPU; +- num_cores_len = sizeof(num_cores); +- if (sysctl(mib, sizeof(mib)/sizeof(int), &num_cores, &num_cores_len, NULL, 0) == 0 && (num_cores > 0)) +- { +- if (num_cores > 0) +- g_num_cores = num_cores; +- } +- } +-#endif +- } +- return g_num_cores; +-} +- +- +- +-#if !defined (__APPLE__) +-bool +-Host::OpenFileInExternalEditor (const FileSpec &file_spec, uint32_t line_no) +-{ +- return false; +-} +- +-void +-Host::SetCrashDescriptionWithFormat (const char *format, ...) +-{ +-} +- +-void +-Host::SetCrashDescription (const char *description) +-{ +-} +- +-lldb::pid_t +-LaunchApplication (const FileSpec &app_file_spec) +-{ +- return LLDB_INVALID_PROCESS_ID; +-} +- +-#endif Index: llvm-toolchain-3.3-3.3/lldb/source/Host/common/Host.cpp =================================================================== --- llvm-toolchain-3.3-3.3.orig/lldb/source/Host/common/Host.cpp 2013-08-28 10:29:30.000000000 +0000 From 78a5add8204cac4cae96aae551562e26ffe59450 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 4 Sep 2013 14:18:44 +0000 Subject: [PATCH 11/14] refresh of the patch --- debian/patches/libprofile_rt_sparc.patch | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/debian/patches/libprofile_rt_sparc.patch b/debian/patches/libprofile_rt_sparc.patch index 5311b81a..27f85302 100644 --- a/debian/patches/libprofile_rt_sparc.patch +++ b/debian/patches/libprofile_rt_sparc.patch @@ -1,7 +1,7 @@ -Index: llvm-toolchain-3.2-3.2repack/runtime/Makefile +Index: llvm-toolchain-3.3-3.3/runtime/Makefile =================================================================== ---- llvm-toolchain-3.2-3.2repack.orig/runtime/Makefile 2010-04-15 21:51:42.000000000 +0200 -+++ llvm-toolchain-3.2-3.2repack/runtime/Makefile 2013-08-23 11:25:15.964131399 +0200 +--- llvm-toolchain-3.3-3.3.orig/runtime/Makefile 2013-08-28 13:16:23.000000000 +0000 ++++ llvm-toolchain-3.3-3.3/runtime/Makefile 2013-08-28 13:16:45.000000000 +0000 @@ -14,12 +14,6 @@ PARALLEL_DIRS := libprofile From 36df6cff64066aafe36faebc66123210b0bdfa5f Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 4 Sep 2013 14:20:10 +0000 Subject: [PATCH 12/14] * Fix 'bits/c++config.h' file not found under i386 See libstdc++-header-i386.diff. (Closes: #714890) * Add more fixes for the HURD port... (but still fails) --- debian/changelog | 4 +++- debian/patches/libstdc++-header-i386.diff | 15 +++++++++++++++ debian/patches/series | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 debian/patches/libstdc++-header-i386.diff diff --git a/debian/changelog b/debian/changelog index 9d7ad07e..d9e15d5c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,7 +7,9 @@ llvm-toolchain-3.3 (1:3.3-9) UNRELEASED; urgency=low [ Sylvestre Ledru ] * Only use -fuse-ld=gold on supported distribution. Simplify the backports. - * Add more fixes for the HURD port... + * Fix 'bits/c++config.h' file not found under i386 + See libstdc++-header-i386.diff. (Closes: #714890) + * Add more fixes for the HURD port... (but still fails) [ Jon Severinsson ] * Merge from llvm-toolchain-3.2 branch up to 3.2repack-11. diff --git a/debian/patches/libstdc++-header-i386.diff b/debian/patches/libstdc++-header-i386.diff new file mode 100644 index 00000000..b157f4da --- /dev/null +++ b/debian/patches/libstdc++-header-i386.diff @@ -0,0 +1,15 @@ +Index: llvm-toolchain-3.3-3.3/clang/lib/Driver/ToolChains.cpp +=================================================================== +--- llvm-toolchain-3.3-3.3.orig/clang/lib/Driver/ToolChains.cpp 2013-09-03 14:04:41.000000000 +0000 ++++ llvm-toolchain-3.3-3.3/clang/lib/Driver/ToolChains.cpp 2013-09-04 14:09:12.000000000 +0000 +@@ -2588,6 +2588,10 @@ + StringRef Version = GCCInstallation.getVersion().Text; + StringRef TripleStr = GCCInstallation.getTriple().str(); + ++ #ifdef __i386__ ++ // clang does not detect this path: /usr/include/i386-linux-gnu/c++/4.8/ Help him ++ addLibStdCXXIncludePaths( "/usr/include/", "/c++/" + Version.str(), "i386-linux-gnu", GCCInstallation.getMultiarchSuffix(), DriverArgs, CC1Args); ++ #endif + if (addLibStdCXXIncludePaths(LibDir.str() + "/../include", + "/c++/" + Version.str(), + TripleStr, diff --git a/debian/patches/series b/debian/patches/series index 0bd98168..eb0f56b6 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -33,4 +33,4 @@ unwind-chain-inclusion.diff hurd-pathmax.diff libprofile_rt_sparc.patch lldb-hurd.diff -lldb-link-atomic.diff +libstdc++-header-i386.diff From 866dfac491041a34726d375906910e60031f2c65 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 4 Sep 2013 20:48:03 +0000 Subject: [PATCH 13/14] fix the patch + release --- debian/changelog | 2 +- debian/patches/hurd-pathmax.diff | 3865 ------------------------------ debian/patches/lldb-hurd.diff | 1520 ------------ 3 files changed, 1 insertion(+), 5386 deletions(-) diff --git a/debian/changelog b/debian/changelog index d9e15d5c..7ab9d71a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -llvm-toolchain-3.3 (1:3.3-9) UNRELEASED; urgency=low +llvm-toolchain-3.3 (1:3.3-9) unstable; urgency=low [ Luca Falavigna ] * debian/control: diff --git a/debian/patches/hurd-pathmax.diff b/debian/patches/hurd-pathmax.diff index c6490467..0abe1eed 100644 --- a/debian/patches/hurd-pathmax.diff +++ b/debian/patches/hurd-pathmax.diff @@ -30,3868 +30,3 @@ Index: llvm-toolchain-3.3-3.3/lldb/include/lldb/lldb-defines.h #if !defined(UINT32_MAX) #define UINT32_MAX 4294967295U #endif -Index: llvm-toolchain-3.3-3.3/home/sylvestre/llvm-toolchain-3.3-3.3/tools/lldb/include/lldb/Target/Process.h -=================================================================== ---- llvm-toolchain-3.3-3.3.orig/home/sylvestre/llvm-toolchain-3.3-3.3/tools/lldb/include/lldb/Target/Process.h 2013-08-28 10:29:30.000000000 +0000 -+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 -@@ -1,3860 +0,0 @@ --//===-- Process.h -----------------------------------------------*- C++ -*-===// --// --// The LLVM Compiler Infrastructure --// --// This file is distributed under the University of Illinois Open Source --// License. See LICENSE.TXT for details. --// --//===----------------------------------------------------------------------===// -- --#ifndef liblldb_Process_h_ --#define liblldb_Process_h_ -- --// C Includes --#include --#include -- --// C++ Includes --#include --#include --#include -- --// Other libraries and framework includes --// Project includes --#include "lldb/lldb-private.h" --#include "lldb/Core/ArchSpec.h" --#include "lldb/Core/Broadcaster.h" --#include "lldb/Core/Communication.h" --#include "lldb/Core/Error.h" --#include "lldb/Core/Event.h" --#include "lldb/Core/RangeMap.h" --#include "lldb/Core/StringList.h" --#include "lldb/Core/ThreadSafeValue.h" --#include "lldb/Core/PluginInterface.h" --#include "lldb/Core/UserSettingsController.h" --#include "lldb/Breakpoint/BreakpointSiteList.h" --#include "lldb/Expression/ClangPersistentVariables.h" --#include "lldb/Expression/IRDynamicChecks.h" --#include "lldb/Host/FileSpec.h" --#include "lldb/Host/Host.h" --#include "lldb/Host/ReadWriteLock.h" --#include "lldb/Interpreter/Args.h" --#include "lldb/Interpreter/Options.h" --#include "lldb/Target/ExecutionContextScope.h" --#include "lldb/Target/Memory.h" --#include "lldb/Target/ThreadList.h" --#include "lldb/Target/UnixSignals.h" --#include "lldb/Utility/PseudoTerminal.h" -- --namespace lldb_private { -- --//---------------------------------------------------------------------- --// ProcessProperties --//---------------------------------------------------------------------- --class ProcessProperties : public Properties --{ --public: -- ProcessProperties(bool is_global); -- -- virtual -- ~ProcessProperties(); -- -- bool -- GetDisableMemoryCache() const; -- -- Args -- GetExtraStartupCommands () const; -- -- void -- SetExtraStartupCommands (const Args &args); -- -- FileSpec -- GetPythonOSPluginPath () const; -- -- void -- SetPythonOSPluginPath (const FileSpec &file); -- -- bool -- GetIgnoreBreakpointsInExpressions () const; -- -- void -- SetIgnoreBreakpointsInExpressions (bool ignore); -- -- bool -- GetUnwindOnErrorInExpressions () const; -- -- void -- SetUnwindOnErrorInExpressions (bool ignore); -- -- bool -- GetStopOnSharedLibraryEvents () const; -- -- void -- SetStopOnSharedLibraryEvents (bool stop); -- -- bool -- GetDetachKeepsStopped () const; -- -- void -- SetDetachKeepsStopped (bool keep_stopped); --}; -- --typedef std::shared_ptr ProcessPropertiesSP; -- --//---------------------------------------------------------------------- --// ProcessInfo --// --// A base class for information for a process. This can be used to fill --// out information for a process prior to launching it, or it can be --// used for an instance of a process and can be filled in with the --// existing values for that process. --//---------------------------------------------------------------------- --class ProcessInfo --{ --public: -- ProcessInfo () : -- m_executable (), -- m_arguments (), -- m_environment (), -- m_uid (UINT32_MAX), -- m_gid (UINT32_MAX), -- m_arch(), -- m_pid (LLDB_INVALID_PROCESS_ID) -- { -- } -- -- ProcessInfo (const char *name, -- const ArchSpec &arch, -- lldb::pid_t pid) : -- m_executable (name, false), -- m_arguments (), -- m_environment(), -- m_uid (UINT32_MAX), -- m_gid (UINT32_MAX), -- m_arch (arch), -- m_pid (pid) -- { -- } -- -- void -- Clear () -- { -- m_executable.Clear(); -- m_arguments.Clear(); -- m_environment.Clear(); -- m_uid = UINT32_MAX; -- m_gid = UINT32_MAX; -- m_arch.Clear(); -- m_pid = LLDB_INVALID_PROCESS_ID; -- } -- -- const char * -- GetName() const -- { -- return m_executable.GetFilename().GetCString(); -- } -- -- size_t -- GetNameLength() const -- { -- return m_executable.GetFilename().GetLength(); -- } -- -- FileSpec & -- GetExecutableFile () -- { -- return m_executable; -- } -- -- void -- SetExecutableFile (const FileSpec &exe_file, bool add_exe_file_as_first_arg) -- { -- if (exe_file) -- { -- m_executable = exe_file; -- if (add_exe_file_as_first_arg) -- { -- char filename[PATH_MAX]; -- if (exe_file.GetPath(filename, sizeof(filename))) -- m_arguments.InsertArgumentAtIndex (0, filename); -- } -- } -- else -- { -- m_executable.Clear(); -- } -- } -- -- const FileSpec & -- GetExecutableFile () const -- { -- return m_executable; -- } -- -- uint32_t -- GetUserID() const -- { -- return m_uid; -- } -- -- uint32_t -- GetGroupID() const -- { -- return m_gid; -- } -- -- bool -- UserIDIsValid () const -- { -- return m_uid != UINT32_MAX; -- } -- -- bool -- GroupIDIsValid () const -- { -- return m_gid != UINT32_MAX; -- } -- -- void -- SetUserID (uint32_t uid) -- { -- m_uid = uid; -- } -- -- void -- SetGroupID (uint32_t gid) -- { -- m_gid = gid; -- } -- -- ArchSpec & -- GetArchitecture () -- { -- return m_arch; -- } -- -- const ArchSpec & -- GetArchitecture () const -- { -- return m_arch; -- } -- -- lldb::pid_t -- GetProcessID () const -- { -- return m_pid; -- } -- -- void -- SetProcessID (lldb::pid_t pid) -- { -- m_pid = pid; -- } -- -- bool -- ProcessIDIsValid() const -- { -- return m_pid != LLDB_INVALID_PROCESS_ID; -- } -- -- void -- Dump (Stream &s, Platform *platform) const; -- -- Args & -- GetArguments () -- { -- return m_arguments; -- } -- -- const Args & -- GetArguments () const -- { -- return m_arguments; -- } -- -- const char * -- GetArg0 () const -- { -- if (m_arg0.empty()) -- return NULL; -- return m_arg0.c_str(); -- } -- -- void -- SetArg0 (const char *arg) -- { -- if (arg && arg[0]) -- m_arg0 = arg; -- else -- m_arg0.clear(); -- } -- -- void -- SetArguments (const Args& args, bool first_arg_is_executable); -- -- void -- SetArguments (char const **argv, bool first_arg_is_executable); -- -- Args & -- GetEnvironmentEntries () -- { -- return m_environment; -- } -- -- const Args & -- GetEnvironmentEntries () const -- { -- return m_environment; -- } -- --protected: -- FileSpec m_executable; -- std::string m_arg0; // argv[0] if supported. If empty, then use m_executable. -- // Not all process plug-ins support specifying an argv[0] -- // that differs from the resolved platform executable -- // (which is in m_executable) -- Args m_arguments; // All program arguments except argv[0] -- Args m_environment; -- uint32_t m_uid; -- uint32_t m_gid; -- ArchSpec m_arch; -- lldb::pid_t m_pid; --}; -- --//---------------------------------------------------------------------- --// ProcessInstanceInfo --// --// Describes an existing process and any discoverable information that --// pertains to that process. --//---------------------------------------------------------------------- --class ProcessInstanceInfo : public ProcessInfo --{ --public: -- ProcessInstanceInfo () : -- ProcessInfo (), -- m_euid (UINT32_MAX), -- m_egid (UINT32_MAX), -- m_parent_pid (LLDB_INVALID_PROCESS_ID) -- { -- } -- -- ProcessInstanceInfo (const char *name, -- const ArchSpec &arch, -- lldb::pid_t pid) : -- ProcessInfo (name, arch, pid), -- m_euid (UINT32_MAX), -- m_egid (UINT32_MAX), -- m_parent_pid (LLDB_INVALID_PROCESS_ID) -- { -- } -- -- void -- Clear () -- { -- ProcessInfo::Clear(); -- m_euid = UINT32_MAX; -- m_egid = UINT32_MAX; -- m_parent_pid = LLDB_INVALID_PROCESS_ID; -- } -- -- uint32_t -- GetEffectiveUserID() const -- { -- return m_euid; -- } -- -- uint32_t -- GetEffectiveGroupID() const -- { -- return m_egid; -- } -- -- bool -- EffectiveUserIDIsValid () const -- { -- return m_euid != UINT32_MAX; -- } -- -- bool -- EffectiveGroupIDIsValid () const -- { -- return m_egid != UINT32_MAX; -- } -- -- void -- SetEffectiveUserID (uint32_t uid) -- { -- m_euid = uid; -- } -- -- void -- SetEffectiveGroupID (uint32_t gid) -- { -- m_egid = gid; -- } -- -- lldb::pid_t -- GetParentProcessID () const -- { -- return m_parent_pid; -- } -- -- void -- SetParentProcessID (lldb::pid_t pid) -- { -- m_parent_pid = pid; -- } -- -- bool -- ParentProcessIDIsValid() const -- { -- return m_parent_pid != LLDB_INVALID_PROCESS_ID; -- } -- -- void -- Dump (Stream &s, Platform *platform) const; -- -- static void -- DumpTableHeader (Stream &s, Platform *platform, bool show_args, bool verbose); -- -- void -- DumpAsTableRow (Stream &s, Platform *platform, bool show_args, bool verbose) const; -- --protected: -- uint32_t m_euid; -- uint32_t m_egid; -- lldb::pid_t m_parent_pid; --}; -- -- --//---------------------------------------------------------------------- --// ProcessLaunchInfo --// --// Describes any information that is required to launch a process. --//---------------------------------------------------------------------- -- --class ProcessLaunchInfo : public ProcessInfo --{ --public: -- -- class FileAction -- { -- public: -- enum Action -- { -- eFileActionNone, -- eFileActionClose, -- eFileActionDuplicate, -- eFileActionOpen -- }; -- -- -- FileAction () : -- m_action (eFileActionNone), -- m_fd (-1), -- m_arg (-1), -- m_path () -- { -- } -- -- void -- Clear() -- { -- m_action = eFileActionNone; -- m_fd = -1; -- m_arg = -1; -- m_path.clear(); -- } -- -- bool -- Close (int fd); -- -- bool -- Duplicate (int fd, int dup_fd); -- -- bool -- Open (int fd, const char *path, bool read, bool write); -- -- static bool -- AddPosixSpawnFileAction (posix_spawn_file_actions_t *file_actions, -- const FileAction *info, -- Log *log, -- Error& error); -- -- int -- GetFD () const -- { -- return m_fd; -- } -- -- Action -- GetAction () const -- { -- return m_action; -- } -- -- int -- GetActionArgument () const -- { -- return m_arg; -- } -- -- const char * -- GetPath () const -- { -- if (m_path.empty()) -- return NULL; -- return m_path.c_str(); -- } -- -- protected: -- Action m_action; // The action for this file -- int m_fd; // An existing file descriptor -- int m_arg; // oflag for eFileActionOpen*, dup_fd for eFileActionDuplicate -- std::string m_path; // A file path to use for opening after fork or posix_spawn -- }; -- -- ProcessLaunchInfo () : -- ProcessInfo(), -- m_working_dir (), -- m_plugin_name (), -- m_shell (), -- m_flags (0), -- m_file_actions (), -- m_pty (), -- m_resume_count (0), -- m_monitor_callback (NULL), -- m_monitor_callback_baton (NULL), -- m_monitor_signals (false) -- { -- } -- -- ProcessLaunchInfo (const char *stdin_path, -- const char *stdout_path, -- const char *stderr_path, -- const char *working_directory, -- uint32_t launch_flags) : -- ProcessInfo(), -- m_working_dir (), -- m_plugin_name (), -- m_shell (), -- m_flags (launch_flags), -- m_file_actions (), -- m_pty (), -- m_resume_count (0), -- m_monitor_callback (NULL), -- m_monitor_callback_baton (NULL), -- m_monitor_signals (false) -- { -- if (stdin_path) -- { -- ProcessLaunchInfo::FileAction file_action; -- const bool read = true; -- const bool write = false; -- if (file_action.Open(STDIN_FILENO, stdin_path, read, write)) -- AppendFileAction (file_action); -- } -- if (stdout_path) -- { -- ProcessLaunchInfo::FileAction file_action; -- const bool read = false; -- const bool write = true; -- if (file_action.Open(STDOUT_FILENO, stdout_path, read, write)) -- AppendFileAction (file_action); -- } -- if (stderr_path) -- { -- ProcessLaunchInfo::FileAction file_action; -- const bool read = false; -- const bool write = true; -- if (file_action.Open(STDERR_FILENO, stderr_path, read, write)) -- AppendFileAction (file_action); -- } -- if (working_directory) -- SetWorkingDirectory(working_directory); -- } -- -- void -- AppendFileAction (const FileAction &info) -- { -- m_file_actions.push_back(info); -- } -- -- bool -- AppendCloseFileAction (int fd) -- { -- FileAction file_action; -- if (file_action.Close (fd)) -- { -- AppendFileAction (file_action); -- return true; -- } -- return false; -- } -- -- bool -- AppendDuplicateFileAction (int fd, int dup_fd) -- { -- FileAction file_action; -- if (file_action.Duplicate (fd, dup_fd)) -- { -- AppendFileAction (file_action); -- return true; -- } -- return false; -- } -- -- bool -- AppendOpenFileAction (int fd, const char *path, bool read, bool write) -- { -- FileAction file_action; -- if (file_action.Open (fd, path, read, write)) -- { -- AppendFileAction (file_action); -- return true; -- } -- return false; -- } -- -- bool -- AppendSuppressFileAction (int fd, bool read, bool write) -- { -- FileAction file_action; -- if (file_action.Open (fd, "/dev/null", read, write)) -- { -- AppendFileAction (file_action); -- return true; -- } -- return false; -- } -- -- void -- FinalizeFileActions (Target *target, -- bool default_to_use_pty); -- -- size_t -- GetNumFileActions () const -- { -- return m_file_actions.size(); -- } -- -- const FileAction * -- GetFileActionAtIndex (size_t idx) const -- { -- if (idx < m_file_actions.size()) -- return &m_file_actions[idx]; -- return NULL; -- } -- -- const FileAction * -- GetFileActionForFD (int fd) const -- { -- for (size_t idx=0, count=m_file_actions.size(); idx < count; ++idx) -- { -- if (m_file_actions[idx].GetFD () == fd) -- return &m_file_actions[idx]; -- } -- return NULL; -- } -- -- Flags & -- GetFlags () -- { -- return m_flags; -- } -- -- const Flags & -- GetFlags () const -- { -- return m_flags; -- } -- -- const char * -- GetWorkingDirectory () const -- { -- if (m_working_dir.empty()) -- return NULL; -- return m_working_dir.c_str(); -- } -- -- void -- SetWorkingDirectory (const char *working_dir) -- { -- if (working_dir && working_dir[0]) -- m_working_dir.assign (working_dir); -- else -- m_working_dir.clear(); -- } -- -- void -- SwapWorkingDirectory (std::string &working_dir) -- { -- m_working_dir.swap (working_dir); -- } -- -- -- const char * -- GetProcessPluginName () const -- { -- if (m_plugin_name.empty()) -- return NULL; -- return m_plugin_name.c_str(); -- } -- -- void -- SetProcessPluginName (const char *plugin) -- { -- if (plugin && plugin[0]) -- m_plugin_name.assign (plugin); -- else -- m_plugin_name.clear(); -- } -- -- const char * -- GetShell () const -- { -- if (m_shell.empty()) -- return NULL; -- return m_shell.c_str(); -- } -- -- void -- SetShell (const char * path) -- { -- if (path && path[0]) -- { -- m_shell.assign (path); -- m_flags.Set (lldb::eLaunchFlagLaunchInShell); -- } -- else -- { -- m_shell.clear(); -- m_flags.Clear (lldb::eLaunchFlagLaunchInShell); -- } -- } -- -- uint32_t -- GetResumeCount () const -- { -- return m_resume_count; -- } -- -- void -- SetResumeCount (uint32_t c) -- { -- m_resume_count = c; -- } -- -- bool -- GetLaunchInSeparateProcessGroup () -- { -- return m_flags.Test(lldb::eLaunchFlagLaunchInSeparateProcessGroup); -- } -- -- void -- SetLaunchInSeparateProcessGroup (bool separate) -- { -- if (separate) -- m_flags.Set(lldb::eLaunchFlagLaunchInSeparateProcessGroup); -- else -- m_flags.Clear (lldb::eLaunchFlagLaunchInSeparateProcessGroup); -- -- } -- -- void -- Clear () -- { -- ProcessInfo::Clear(); -- m_working_dir.clear(); -- m_plugin_name.clear(); -- m_shell.clear(); -- m_flags.Clear(); -- m_file_actions.clear(); -- m_resume_count = 0; -- } -- -- bool -- ConvertArgumentsForLaunchingInShell (Error &error, -- bool localhost, -- bool will_debug, -- bool first_arg_is_full_shell_command); -- -- void -- SetMonitorProcessCallback (Host::MonitorChildProcessCallback callback, -- void *baton, -- bool monitor_signals) -- { -- m_monitor_callback = callback; -- m_monitor_callback_baton = baton; -- m_monitor_signals = monitor_signals; -- } -- -- bool -- MonitorProcess () const -- { -- if (m_monitor_callback && ProcessIDIsValid()) -- { -- Host::StartMonitoringChildProcess (m_monitor_callback, -- m_monitor_callback_baton, -- GetProcessID(), -- m_monitor_signals); -- return true; -- } -- return false; -- } -- -- lldb_utility::PseudoTerminal & -- GetPTY () -- { -- return m_pty; -- } -- --protected: -- std::string m_working_dir; -- std::string m_plugin_name; -- std::string m_shell; -- Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags -- std::vector m_file_actions; // File actions for any other files -- lldb_utility::PseudoTerminal m_pty; -- uint32_t m_resume_count; // How many times do we resume after launching -- Host::MonitorChildProcessCallback m_monitor_callback; -- void *m_monitor_callback_baton; -- bool m_monitor_signals; -- --}; -- --//---------------------------------------------------------------------- --// ProcessLaunchInfo --// --// Describes any information that is required to launch a process. --//---------------------------------------------------------------------- -- --class ProcessAttachInfo : public ProcessInstanceInfo --{ --public: -- ProcessAttachInfo() : -- ProcessInstanceInfo(), -- m_plugin_name (), -- m_resume_count (0), -- m_wait_for_launch (false), -- m_ignore_existing (true), -- m_continue_once_attached (false) -- { -- } -- -- ProcessAttachInfo (const ProcessLaunchInfo &launch_info) : -- ProcessInstanceInfo(), -- m_plugin_name (), -- m_resume_count (0), -- m_wait_for_launch (false), -- m_ignore_existing (true), -- m_continue_once_attached (false) -- { -- ProcessInfo::operator= (launch_info); -- SetProcessPluginName (launch_info.GetProcessPluginName()); -- SetResumeCount (launch_info.GetResumeCount()); -- } -- -- bool -- GetWaitForLaunch () const -- { -- return m_wait_for_launch; -- } -- -- void -- SetWaitForLaunch (bool b) -- { -- m_wait_for_launch = b; -- } -- -- bool -- GetIgnoreExisting () const -- { -- return m_ignore_existing; -- } -- -- void -- SetIgnoreExisting (bool b) -- { -- m_ignore_existing = b; -- } -- -- bool -- GetContinueOnceAttached () const -- { -- return m_continue_once_attached; -- } -- -- void -- SetContinueOnceAttached (bool b) -- { -- m_continue_once_attached = b; -- } -- -- uint32_t -- GetResumeCount () const -- { -- return m_resume_count; -- } -- -- void -- SetResumeCount (uint32_t c) -- { -- m_resume_count = c; -- } -- -- const char * -- GetProcessPluginName () const -- { -- if (m_plugin_name.empty()) -- return NULL; -- return m_plugin_name.c_str(); -- } -- -- void -- SetProcessPluginName (const char *plugin) -- { -- if (plugin && plugin[0]) -- m_plugin_name.assign (plugin); -- else -- m_plugin_name.clear(); -- } -- -- void -- Clear () -- { -- ProcessInstanceInfo::Clear(); -- m_plugin_name.clear(); -- m_resume_count = 0; -- m_wait_for_launch = false; -- m_ignore_existing = true; -- m_continue_once_attached = false; -- } -- -- bool -- ProcessInfoSpecified () const -- { -- if (GetExecutableFile()) -- return true; -- if (GetProcessID() != LLDB_INVALID_PROCESS_ID) -- return true; -- if (GetParentProcessID() != LLDB_INVALID_PROCESS_ID) -- return true; -- return false; -- } --protected: -- std::string m_plugin_name; -- uint32_t m_resume_count; // How many times do we resume after launching -- bool m_wait_for_launch; -- bool m_ignore_existing; -- bool m_continue_once_attached; // Supports the use-case scenario of immediately continuing the process once attached. --}; -- --class ProcessLaunchCommandOptions : public Options --{ --public: -- -- ProcessLaunchCommandOptions (CommandInterpreter &interpreter) : -- Options(interpreter) -- { -- // Keep default values of all options in one place: OptionParsingStarting () -- OptionParsingStarting (); -- } -- -- ~ProcessLaunchCommandOptions () -- { -- } -- -- Error -- SetOptionValue (uint32_t option_idx, const char *option_arg); -- -- void -- OptionParsingStarting () -- { -- launch_info.Clear(); -- } -- -- const OptionDefinition* -- GetDefinitions () -- { -- return g_option_table; -- } -- -- // Options table: Required for subclasses of Options. -- -- static OptionDefinition g_option_table[]; -- -- // Instance variables to hold the values for command options. -- -- ProcessLaunchInfo launch_info; --}; -- --//---------------------------------------------------------------------- --// ProcessInstanceInfoMatch --// --// A class to help matching one ProcessInstanceInfo to another. --//---------------------------------------------------------------------- -- --class ProcessInstanceInfoMatch --{ --public: -- ProcessInstanceInfoMatch () : -- m_match_info (), -- m_name_match_type (eNameMatchIgnore), -- m_match_all_users (false) -- { -- } -- -- ProcessInstanceInfoMatch (const char *process_name, -- NameMatchType process_name_match_type) : -- m_match_info (), -- m_name_match_type (process_name_match_type), -- m_match_all_users (false) -- { -- m_match_info.GetExecutableFile().SetFile(process_name, false); -- } -- -- ProcessInstanceInfo & -- GetProcessInfo () -- { -- return m_match_info; -- } -- -- const ProcessInstanceInfo & -- GetProcessInfo () const -- { -- return m_match_info; -- } -- -- bool -- GetMatchAllUsers () const -- { -- return m_match_all_users; -- } -- -- void -- SetMatchAllUsers (bool b) -- { -- m_match_all_users = b; -- } -- -- NameMatchType -- GetNameMatchType () const -- { -- return m_name_match_type; -- } -- -- void -- SetNameMatchType (NameMatchType name_match_type) -- { -- m_name_match_type = name_match_type; -- } -- -- bool -- NameMatches (const char *process_name) const; -- -- bool -- Matches (const ProcessInstanceInfo &proc_info) const; -- -- bool -- MatchAllProcesses () const; -- void -- Clear (); -- --protected: -- ProcessInstanceInfo m_match_info; -- NameMatchType m_name_match_type; -- bool m_match_all_users; --}; -- --class ProcessInstanceInfoList --{ --public: -- ProcessInstanceInfoList () : -- m_infos() -- { -- } -- -- void -- Clear() -- { -- m_infos.clear(); -- } -- -- size_t -- GetSize() -- { -- return m_infos.size(); -- } -- -- void -- Append (const ProcessInstanceInfo &info) -- { -- m_infos.push_back (info); -- } -- -- const char * -- GetProcessNameAtIndex (size_t idx) -- { -- if (idx < m_infos.size()) -- return m_infos[idx].GetName(); -- return NULL; -- } -- -- size_t -- GetProcessNameLengthAtIndex (size_t idx) -- { -- if (idx < m_infos.size()) -- return m_infos[idx].GetNameLength(); -- return 0; -- } -- -- lldb::pid_t -- GetProcessIDAtIndex (size_t idx) -- { -- if (idx < m_infos.size()) -- return m_infos[idx].GetProcessID(); -- return 0; -- } -- -- bool -- GetInfoAtIndex (size_t idx, ProcessInstanceInfo &info) -- { -- if (idx < m_infos.size()) -- { -- info = m_infos[idx]; -- return true; -- } -- return false; -- } -- -- // You must ensure "idx" is valid before calling this function -- const ProcessInstanceInfo & -- GetProcessInfoAtIndex (size_t idx) const -- { -- assert (idx < m_infos.size()); -- return m_infos[idx]; -- } -- --protected: -- typedef std::vector collection; -- collection m_infos; --}; -- -- --// This class tracks the Modification state of the process. Things that can currently modify --// the program are running the program (which will up the StopID) and writing memory (which --// will up the MemoryID.) --// FIXME: Should we also include modification of register states? -- --class ProcessModID --{ --friend bool operator== (const ProcessModID &lhs, const ProcessModID &rhs); --public: -- ProcessModID () : -- m_stop_id (0), -- m_last_natural_stop_id(0), -- m_resume_id (0), -- m_memory_id (0), -- m_last_user_expression_resume (0), -- m_running_user_expression (false) -- {} -- -- ProcessModID (const ProcessModID &rhs) : -- m_stop_id (rhs.m_stop_id), -- m_memory_id (rhs.m_memory_id) -- {} -- -- const ProcessModID & operator= (const ProcessModID &rhs) -- { -- if (this != &rhs) -- { -- m_stop_id = rhs.m_stop_id; -- m_memory_id = rhs.m_memory_id; -- } -- return *this; -- } -- -- ~ProcessModID () {} -- -- void BumpStopID () { -- m_stop_id++; -- if (!IsLastResumeForUserExpression()) -- m_last_natural_stop_id++; -- } -- -- void BumpMemoryID () { m_memory_id++; } -- -- void BumpResumeID () { -- m_resume_id++; -- if (m_running_user_expression > 0) -- m_last_user_expression_resume = m_resume_id; -- } -- -- uint32_t GetStopID() const { return m_stop_id; } -- uint32_t GetLastNaturalStopID() const { return m_last_natural_stop_id; } -- uint32_t GetMemoryID () const { return m_memory_id; } -- uint32_t GetResumeID () const { return m_resume_id; } -- uint32_t GetLastUserExpressionResumeID () const { return m_last_user_expression_resume; } -- -- bool MemoryIDEqual (const ProcessModID &compare) const -- { -- return m_memory_id == compare.m_memory_id; -- } -- -- bool StopIDEqual (const ProcessModID &compare) const -- { -- return m_stop_id == compare.m_stop_id; -- } -- -- void SetInvalid () -- { -- m_stop_id = UINT32_MAX; -- } -- -- bool IsValid () const -- { -- return m_stop_id != UINT32_MAX; -- } -- -- bool -- IsLastResumeForUserExpression () const -- { -- return m_resume_id == m_last_user_expression_resume; -- } -- -- void -- SetRunningUserExpression (bool on) -- { -- // REMOVEME printf ("Setting running user expression %s at resume id %d - value: %d.\n", on ? "on" : "off", m_resume_id, m_running_user_expression); -- if (on) -- m_running_user_expression++; -- else -- m_running_user_expression--; -- } -- --private: -- uint32_t m_stop_id; -- uint32_t m_last_natural_stop_id; -- uint32_t m_resume_id; -- uint32_t m_memory_id; -- uint32_t m_last_user_expression_resume; -- uint32_t m_running_user_expression; --}; --inline bool operator== (const ProcessModID &lhs, const ProcessModID &rhs) --{ -- if (lhs.StopIDEqual (rhs) -- && lhs.MemoryIDEqual (rhs)) -- return true; -- else -- return false; --} -- --inline bool operator!= (const ProcessModID &lhs, const ProcessModID &rhs) --{ -- if (!lhs.StopIDEqual (rhs) -- || !lhs.MemoryIDEqual (rhs)) -- return true; -- else -- return false; --} -- --class MemoryRegionInfo --{ --public: -- typedef Range RangeType; -- -- enum OptionalBool { -- eDontKnow = -1, -- eNo = 0, -- eYes = 1 -- }; -- -- MemoryRegionInfo () : -- m_range (), -- m_read (eDontKnow), -- m_write (eDontKnow), -- m_execute (eDontKnow) -- { -- } -- -- ~MemoryRegionInfo () -- { -- } -- -- RangeType & -- GetRange() -- { -- return m_range; -- } -- -- void -- Clear() -- { -- m_range.Clear(); -- m_read = m_write = m_execute = eDontKnow; -- } -- -- const RangeType & -- GetRange() const -- { -- return m_range; -- } -- -- OptionalBool -- GetReadable () const -- { -- return m_read; -- } -- -- OptionalBool -- GetWritable () const -- { -- return m_write; -- } -- -- OptionalBool -- GetExecutable () const -- { -- return m_execute; -- } -- -- void -- SetReadable (OptionalBool val) -- { -- m_read = val; -- } -- -- void -- SetWritable (OptionalBool val) -- { -- m_write = val; -- } -- -- void -- SetExecutable (OptionalBool val) -- { -- m_execute = val; -- } -- --protected: -- RangeType m_range; -- OptionalBool m_read; -- OptionalBool m_write; -- OptionalBool m_execute; --}; -- --//---------------------------------------------------------------------- --/// @class Process Process.h "lldb/Target/Process.h" --/// @brief A plug-in interface definition class for debugging a process. --//---------------------------------------------------------------------- --class Process : -- public std::enable_shared_from_this, -- public ProcessProperties, -- public UserID, -- public Broadcaster, -- public ExecutionContextScope, -- public PluginInterface --{ --friend class ThreadList; --friend class ClangFunction; // For WaitForStateChangeEventsPrivate --friend class CommandObjectProcessLaunch; --friend class ProcessEventData; --friend class CommandObjectBreakpointCommand; --friend class StopInfo; -- --public: -- -- //------------------------------------------------------------------ -- /// Broadcaster event bits definitions. -- //------------------------------------------------------------------ -- enum -- { -- eBroadcastBitStateChanged = (1 << 0), -- eBroadcastBitInterrupt = (1 << 1), -- eBroadcastBitSTDOUT = (1 << 2), -- eBroadcastBitSTDERR = (1 << 3), -- eBroadcastBitProfileData = (1 << 4) -- }; -- -- enum -- { -- eBroadcastInternalStateControlStop = (1<<0), -- eBroadcastInternalStateControlPause = (1<<1), -- eBroadcastInternalStateControlResume = (1<<2) -- }; -- -- typedef Range LoadRange; -- // We use a read/write lock to allow on or more clients to -- // access the process state while the process is stopped (reader). -- // We lock the write lock to control access to the process -- // while it is running (readers, or clients that want the process -- // stopped can block waiting for the process to stop, or just -- // try to lock it to see if they can immediately access the stopped -- // process. If the try read lock fails, then the process is running. -- typedef ReadWriteLock::ReadLocker StopLocker; -- typedef ReadWriteLock::WriteLocker RunLocker; -- -- // These two functions fill out the Broadcaster interface: -- -- static ConstString &GetStaticBroadcasterClass (); -- -- virtual ConstString &GetBroadcasterClass() const -- { -- return GetStaticBroadcasterClass(); -- } -- -- -- //------------------------------------------------------------------ -- /// A notification structure that can be used by clients to listen -- /// for changes in a process's lifetime. -- /// -- /// @see RegisterNotificationCallbacks (const Notifications&) -- /// @see UnregisterNotificationCallbacks (const Notifications&) -- //------------------------------------------------------------------ --#ifndef SWIG -- typedef struct -- { -- void *baton; -- void (*initialize)(void *baton, Process *process); -- void (*process_state_changed) (void *baton, Process *process, lldb::StateType state); -- } Notifications; -- -- class ProcessEventData : -- public EventData -- { -- friend class Process; -- -- public: -- ProcessEventData (); -- ProcessEventData (const lldb::ProcessSP &process, lldb::StateType state); -- -- virtual ~ProcessEventData(); -- -- static const ConstString & -- GetFlavorString (); -- -- virtual const ConstString & -- GetFlavor () const; -- -- const lldb::ProcessSP & -- GetProcessSP() const -- { -- return m_process_sp; -- } -- lldb::StateType -- GetState() const -- { -- return m_state; -- } -- bool -- GetRestarted () const -- { -- return m_restarted; -- } -- -- size_t -- GetNumRestartedReasons () -- { -- return m_restarted_reasons.size(); -- } -- -- const char * -- GetRestartedReasonAtIndex(size_t idx) -- { -- if (idx > m_restarted_reasons.size()) -- return NULL; -- else -- return m_restarted_reasons[idx].c_str(); -- } -- -- bool -- GetInterrupted () const -- { -- return m_interrupted; -- } -- -- virtual void -- Dump (Stream *s) const; -- -- virtual void -- DoOnRemoval (Event *event_ptr); -- -- static const Process::ProcessEventData * -- GetEventDataFromEvent (const Event *event_ptr); -- -- static lldb::ProcessSP -- GetProcessFromEvent (const Event *event_ptr); -- -- static lldb::StateType -- GetStateFromEvent (const Event *event_ptr); -- -- static bool -- GetRestartedFromEvent (const Event *event_ptr); -- -- static size_t -- GetNumRestartedReasons(const Event *event_ptr); -- -- static const char * -- GetRestartedReasonAtIndex(const Event *event_ptr, size_t idx); -- -- static void -- AddRestartedReason (Event *event_ptr, const char *reason); -- -- static void -- SetRestartedInEvent (Event *event_ptr, bool new_value); -- -- static bool -- GetInterruptedFromEvent (const Event *event_ptr); -- -- static void -- SetInterruptedInEvent (Event *event_ptr, bool new_value); -- -- static bool -- SetUpdateStateOnRemoval (Event *event_ptr); -- -- private: -- -- void -- SetUpdateStateOnRemoval() -- { -- m_update_state++; -- } -- void -- SetRestarted (bool new_value) -- { -- m_restarted = new_value; -- } -- void -- SetInterrupted (bool new_value) -- { -- m_interrupted = new_value; -- } -- void -- AddRestartedReason (const char *reason) -- { -- m_restarted_reasons.push_back(reason); -- } -- -- lldb::ProcessSP m_process_sp; -- lldb::StateType m_state; -- std::vector m_restarted_reasons; -- bool m_restarted; // For "eStateStopped" events, this is true if the target was automatically restarted. -- int m_update_state; -- bool m_interrupted; -- DISALLOW_COPY_AND_ASSIGN (ProcessEventData); -- -- }; -- --#endif -- -- static void -- SettingsInitialize (); -- -- static void -- SettingsTerminate (); -- -- static const ProcessPropertiesSP & -- GetGlobalProperties(); -- -- //------------------------------------------------------------------ -- /// Construct with a shared pointer to a target, and the Process listener. -- //------------------------------------------------------------------ -- Process(Target &target, Listener &listener); -- -- //------------------------------------------------------------------ -- /// Destructor. -- /// -- /// The destructor is virtual since this class is designed to be -- /// inherited from by the plug-in instance. -- //------------------------------------------------------------------ -- virtual -- ~Process(); -- -- //------------------------------------------------------------------ -- /// Find a Process plug-in that can debug \a module using the -- /// currently selected architecture. -- /// -- /// Scans all loaded plug-in interfaces that implement versions of -- /// the Process plug-in interface and returns the first instance -- /// that can debug the file. -- /// -- /// @param[in] module_sp -- /// The module shared pointer that this process will debug. -- /// -- /// @param[in] plugin_name -- /// If NULL, select the best plug-in for the binary. If non-NULL -- /// then look for a plugin whose PluginInfo's name matches -- /// this string. -- /// -- /// @see Process::CanDebug () -- //------------------------------------------------------------------ -- static lldb::ProcessSP -- FindPlugin (Target &target, -- const char *plugin_name, -- Listener &listener, -- const FileSpec *crash_file_path); -- -- -- -- //------------------------------------------------------------------ -- /// Static function that can be used with the \b host function -- /// Host::StartMonitoringChildProcess (). -- /// -- /// This function can be used by lldb_private::Process subclasses -- /// when they want to watch for a local process and have its exit -- /// status automatically set when the host child process exits. -- /// Subclasses should call Host::StartMonitoringChildProcess () -- /// with: -- /// callback = Process::SetHostProcessExitStatus -- /// callback_baton = NULL -- /// pid = Process::GetID() -- /// monitor_signals = false -- //------------------------------------------------------------------ -- static bool -- SetProcessExitStatus (void *callback_baton, // The callback baton which should be set to NULL -- lldb::pid_t pid, // The process ID we want to monitor -- bool exited, -- int signo, // Zero for no signal -- int status); // Exit value of process if signal is zero -- -- lldb::ByteOrder -- GetByteOrder () const; -- -- uint32_t -- GetAddressByteSize () const; -- -- uint32_t -- GetUniqueID() const -- { -- return m_process_unique_id; -- } -- //------------------------------------------------------------------ -- /// Check if a plug-in instance can debug the file in \a module. -- /// -- /// Each plug-in is given a chance to say whether it can debug -- /// the file in \a module. If the Process plug-in instance can -- /// debug a file on the current system, it should return \b true. -- /// -- /// @return -- /// Returns \b true if this Process plug-in instance can -- /// debug the executable, \b false otherwise. -- //------------------------------------------------------------------ -- virtual bool -- CanDebug (Target &target, -- bool plugin_specified_by_name) = 0; -- -- -- //------------------------------------------------------------------ -- /// This object is about to be destroyed, do any necessary cleanup. -- /// -- /// Subclasses that override this method should always call this -- /// superclass method. -- //------------------------------------------------------------------ -- virtual void -- Finalize(); -- -- -- //------------------------------------------------------------------ -- /// Return whether this object is valid (i.e. has not been finalized.) -- /// -- /// @return -- /// Returns \b true if this Process has not been finalized -- /// and \b false otherwise. -- //------------------------------------------------------------------ -- bool -- IsValid() const -- { -- return !m_finalize_called; -- } -- -- //------------------------------------------------------------------ -- /// Return a multi-word command object that can be used to expose -- /// plug-in specific commands. -- /// -- /// This object will be used to resolve plug-in commands and can be -- /// triggered by a call to: -- /// -- /// (lldb) process commmand -- /// -- /// @return -- /// A CommandObject which can be one of the concrete subclasses -- /// of CommandObject like CommandObjectRaw, CommandObjectParsed, -- /// or CommandObjectMultiword. -- //------------------------------------------------------------------ -- virtual CommandObject * -- GetPluginCommandObject() -- { -- return NULL; -- } -- -- //------------------------------------------------------------------ -- /// Launch a new process. -- /// -- /// Launch a new process by spawning a new process using the -- /// target object's executable module's file as the file to launch. -- /// Arguments are given in \a argv, and the environment variables -- /// are in \a envp. Standard input and output files can be -- /// optionally re-directed to \a stdin_path, \a stdout_path, and -- /// \a stderr_path. -- /// -- /// This function is not meant to be overridden by Process -- /// subclasses. It will first call Process::WillLaunch (Module *) -- /// and if that returns \b true, Process::DoLaunch (Module*, -- /// char const *[],char const *[],const char *,const char *, -- /// const char *) will be called to actually do the launching. If -- /// DoLaunch returns \b true, then Process::DidLaunch() will be -- /// called. -- /// -- /// @param[in] argv -- /// The argument array. -- /// -- /// @param[in] envp -- /// The environment array. -- /// -- /// @param[in] launch_flags -- /// Flags to modify the launch (@see lldb::LaunchFlags) -- /// -- /// @param[in] stdin_path -- /// The path to use when re-directing the STDIN of the new -- /// process. If all stdXX_path arguments are NULL, a pseudo -- /// terminal will be used. -- /// -- /// @param[in] stdout_path -- /// The path to use when re-directing the STDOUT of the new -- /// process. If all stdXX_path arguments are NULL, a pseudo -- /// terminal will be used. -- /// -- /// @param[in] stderr_path -- /// The path to use when re-directing the STDERR of the new -- /// process. If all stdXX_path arguments are NULL, a pseudo -- /// terminal will be used. -- /// -- /// @param[in] working_directory -- /// The working directory to have the child process run in -- /// -- /// @return -- /// An error object. Call GetID() to get the process ID if -- /// the error object is success. -- //------------------------------------------------------------------ -- virtual Error -- Launch (const ProcessLaunchInfo &launch_info); -- -- virtual Error -- LoadCore (); -- -- virtual Error -- DoLoadCore () -- { -- Error error; -- error.SetErrorStringWithFormat("error: %s does not support loading core files.", GetPluginName().GetCString()); -- return error; -- } -- -- //------------------------------------------------------------------ -- /// Get the dynamic loader plug-in for this process. -- /// -- /// The default action is to let the DynamicLoader plug-ins check -- /// the main executable and the DynamicLoader will select itself -- /// automatically. Subclasses can override this if inspecting the -- /// executable is not desired, or if Process subclasses can only -- /// use a specific DynamicLoader plug-in. -- //------------------------------------------------------------------ -- virtual DynamicLoader * -- GetDynamicLoader (); -- -- //------------------------------------------------------------------ -- /// Attach to an existing process using the process attach info. -- /// -- /// This function is not meant to be overridden by Process -- /// subclasses. It will first call WillAttach (lldb::pid_t) -- /// or WillAttach (const char *), and if that returns \b -- /// true, DoAttach (lldb::pid_t) or DoAttach (const char *) will -- /// be called to actually do the attach. If DoAttach returns \b -- /// true, then Process::DidAttach() will be called. -- /// -- /// @param[in] pid -- /// The process ID that we should attempt to attach to. -- /// -- /// @return -- /// Returns \a pid if attaching was successful, or -- /// LLDB_INVALID_PROCESS_ID if attaching fails. -- //------------------------------------------------------------------ -- virtual Error -- Attach (ProcessAttachInfo &attach_info); -- -- //------------------------------------------------------------------ -- /// Attach to a remote system via a URL -- /// -- /// @param[in] strm -- /// A stream where output intended for the user -- /// (if the driver has a way to display that) generated during -- /// the connection. This may be NULL if no output is needed.A -- /// -- /// @param[in] remote_url -- /// The URL format that we are connecting to. -- /// -- /// @return -- /// Returns an error object. -- //------------------------------------------------------------------ -- virtual Error -- ConnectRemote (Stream *strm, const char *remote_url); -- -- bool -- GetShouldDetach () const -- { -- return m_should_detach; -- } -- -- void -- SetShouldDetach (bool b) -- { -- m_should_detach = b; -- } -- -- //------------------------------------------------------------------ -- /// Get the image information address for the current process. -- /// -- /// Some runtimes have system functions that can help dynamic -- /// loaders locate the dynamic loader information needed to observe -- /// shared libraries being loaded or unloaded. This function is -- /// in the Process interface (as opposed to the DynamicLoader -- /// interface) to ensure that remote debugging can take advantage of -- /// this functionality. -- /// -- /// @return -- /// The address of the dynamic loader information, or -- /// LLDB_INVALID_ADDRESS if this is not supported by this -- /// interface. -- //------------------------------------------------------------------ -- virtual lldb::addr_t -- GetImageInfoAddress (); -- -- //------------------------------------------------------------------ -- /// Load a shared library into this process. -- /// -- /// Try and load a shared library into the current process. This -- /// call might fail in the dynamic loader plug-in says it isn't safe -- /// to try and load shared libraries at the moment. -- /// -- /// @param[in] image_spec -- /// The image file spec that points to the shared library that -- /// you want to load. -- /// -- /// @param[out] error -- /// An error object that gets filled in with any errors that -- /// might occur when trying to load the shared library. -- /// -- /// @return -- /// A token that represents the shared library that can be -- /// later used to unload the shared library. A value of -- /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared -- /// library can't be opened. -- //------------------------------------------------------------------ -- virtual uint32_t -- LoadImage (const FileSpec &image_spec, Error &error); -- -- virtual Error -- UnloadImage (uint32_t image_token); -- -- //------------------------------------------------------------------ -- /// Register for process and thread notifications. -- /// -- /// Clients can register nofication callbacks by filling out a -- /// Process::Notifications structure and calling this function. -- /// -- /// @param[in] callbacks -- /// A structure that contains the notification baton and -- /// callback functions. -- /// -- /// @see Process::Notifications -- //------------------------------------------------------------------ --#ifndef SWIG -- void -- RegisterNotificationCallbacks (const Process::Notifications& callbacks); --#endif -- //------------------------------------------------------------------ -- /// Unregister for process and thread notifications. -- /// -- /// Clients can unregister nofication callbacks by passing a copy of -- /// the original baton and callbacks in \a callbacks. -- /// -- /// @param[in] callbacks -- /// A structure that contains the notification baton and -- /// callback functions. -- /// -- /// @return -- /// Returns \b true if the notification callbacks were -- /// successfully removed from the process, \b false otherwise. -- /// -- /// @see Process::Notifications -- //------------------------------------------------------------------ --#ifndef SWIG -- bool -- UnregisterNotificationCallbacks (const Process::Notifications& callbacks); --#endif -- //================================================================== -- // Built in Process Control functions -- //================================================================== -- //------------------------------------------------------------------ -- /// Resumes all of a process's threads as configured using the -- /// Thread run control functions. -- /// -- /// Threads for a process should be updated with one of the run -- /// control actions (resume, step, or suspend) that they should take -- /// when the process is resumed. If no run control action is given -- /// to a thread it will be resumed by default. -- /// -- /// This function is not meant to be overridden by Process -- /// subclasses. This function will take care of disabling any -- /// breakpoints that threads may be stopped at, single stepping, and -- /// re-enabling breakpoints, and enabling the basic flow control -- /// that the plug-in instances need not worry about. -- /// -- /// N.B. This function also sets the Write side of the Run Lock, -- /// which is unset when the corresponding stop event is pulled off -- /// the Public Event Queue. If you need to resume the process without -- /// setting the Run Lock, use PrivateResume (though you should only do -- /// that from inside the Process class. -- /// -- /// @return -- /// Returns an error object. -- /// -- /// @see Thread:Resume() -- /// @see Thread:Step() -- /// @see Thread:Suspend() -- //------------------------------------------------------------------ -- Error -- Resume(); -- -- //------------------------------------------------------------------ -- /// Halts a running process. -- /// -- /// This function is not meant to be overridden by Process -- /// subclasses. -- /// If the process is successfully halted, a eStateStopped -- /// process event with GetInterrupted will be broadcast. If false, we will -- /// halt the process with no events generated by the halt. -- /// -- /// @param[in] clear_thread_plans -- /// If true, when the process stops, clear all thread plans. -- /// -- /// @return -- /// Returns an error object. If the error is empty, the process is halted. -- /// otherwise the halt has failed. -- //------------------------------------------------------------------ -- Error -- Halt (bool clear_thread_plans = false); -- -- //------------------------------------------------------------------ -- /// Detaches from a running or stopped process. -- /// -- /// This function is not meant to be overridden by Process -- /// subclasses. -- /// -- /// @param[in] keep_stopped -- /// If true, don't resume the process on detach. -- /// -- /// @return -- /// Returns an error object. -- //------------------------------------------------------------------ -- Error -- Detach (bool keep_stopped); -- -- //------------------------------------------------------------------ -- /// Kills the process and shuts down all threads that were spawned -- /// to track and monitor the process. -- /// -- /// This function is not meant to be overridden by Process -- /// subclasses. -- /// -- /// @return -- /// Returns an error object. -- //------------------------------------------------------------------ -- Error -- Destroy(); -- -- //------------------------------------------------------------------ -- /// Sends a process a UNIX signal \a signal. -- /// -- /// This function is not meant to be overridden by Process -- /// subclasses. -- /// -- /// @return -- /// Returns an error object. -- //------------------------------------------------------------------ -- Error -- Signal (int signal); -- -- virtual UnixSignals & -- GetUnixSignals () -- { -- return m_unix_signals; -- } -- -- //================================================================== -- // Plug-in Process Control Overrides -- //================================================================== -- -- //------------------------------------------------------------------ -- /// Called before attaching to a process. -- /// -- /// Allow Process plug-ins to execute some code before attaching a -- /// process. -- /// -- /// @return -- /// Returns an error object. -- //------------------------------------------------------------------ -- virtual Error -- WillAttachToProcessWithID (lldb::pid_t pid) -- { -- return Error(); -- } -- -- //------------------------------------------------------------------ -- /// Called before attaching to a process. -- /// -- /// Allow Process plug-ins to execute some code before attaching a -- /// process. -- /// -- /// @return -- /// Returns an error object. -- //------------------------------------------------------------------ -- virtual Error -- WillAttachToProcessWithName (const char *process_name, bool wait_for_launch) -- { -- return Error(); -- } -- -- //------------------------------------------------------------------ -- /// Attach to a remote system via a URL -- /// -- /// @param[in] strm -- /// A stream where output intended for the user -- /// (if the driver has a way to display that) generated during -- /// the connection. This may be NULL if no output is needed.A -- /// -- /// @param[in] remote_url -- /// The URL format that we are connecting to. -- /// -- /// @return -- /// Returns an error object. -- //------------------------------------------------------------------ -- virtual Error -- DoConnectRemote (Stream *strm, const char *remote_url) -- { -- Error error; -- error.SetErrorString ("remote connections are not supported"); -- return error; -- } -- -- //------------------------------------------------------------------ -- /// Attach to an existing process using a process ID. -- /// -- /// @param[in] pid -- /// The process ID that we should attempt to attach to. -- /// -- /// @return -- /// Returns \a pid if attaching was successful, or -- /// LLDB_INVALID_PROCESS_ID if attaching fails. -- //------------------------------------------------------------------ -- virtual Error -- DoAttachToProcessWithID (lldb::pid_t pid) -- { -- Error error; -- error.SetErrorStringWithFormat("error: %s does not support attaching to a process by pid", GetPluginName().GetCString()); -- return error; -- } -- -- //------------------------------------------------------------------ -- /// Attach to an existing process using a process ID. -- /// -- /// @param[in] pid -- /// The process ID that we should attempt to attach to. -- /// -- /// @param[in] attach_info -- /// Information on how to do the attach. For example, GetUserID() -- /// will return the uid to attach as. -- /// -- /// @return -- /// Returns \a pid if attaching was successful, or -- /// LLDB_INVALID_PROCESS_ID if attaching fails. -- /// hanming : need flag -- //------------------------------------------------------------------ -- virtual Error -- DoAttachToProcessWithID (lldb::pid_t pid, const ProcessAttachInfo &attach_info) -- { -- Error error; -- error.SetErrorStringWithFormat("error: %s does not support attaching to a process by pid", GetPluginName().GetCString()); -- return error; -- } -- -- //------------------------------------------------------------------ -- /// Attach to an existing process using a partial process name. -- /// -- /// @param[in] process_name -- /// The name of the process to attach to. -- /// -- /// @param[in] wait_for_launch -- /// If \b true, wait for the process to be launched and attach -- /// as soon as possible after it does launch. If \b false, then -- /// search for a matching process the currently exists. -- /// -- /// @param[in] attach_info -- /// Information on how to do the attach. For example, GetUserID() -- /// will return the uid to attach as. -- /// -- /// @return -- /// Returns \a pid if attaching was successful, or -- /// LLDB_INVALID_PROCESS_ID if attaching fails. -- //------------------------------------------------------------------ -- virtual Error -- DoAttachToProcessWithName (const char *process_name, bool wait_for_launch, const ProcessAttachInfo &attach_info) -- { -- Error error; -- error.SetErrorString("attach by name is not supported"); -- return error; -- } -- -- //------------------------------------------------------------------ -- /// Called after attaching a process. -- /// -- /// Allow Process plug-ins to execute some code after attaching to -- /// a process. -- //------------------------------------------------------------------ -- virtual void -- DidAttach () {} -- -- -- //------------------------------------------------------------------ -- /// Called after a process re-execs itself. -- /// -- /// Allow Process plug-ins to execute some code after a process has -- /// exec'ed itself. Subclasses typically should override DoDidExec() -- /// as the lldb_private::Process class needs to remove its dynamic -- /// loader, runtime, ABI and other plug-ins, as well as unload all -- /// shared libraries. -- //------------------------------------------------------------------ -- virtual void -- DidExec (); -- -- //------------------------------------------------------------------ -- /// Subclasses of Process should implement this function if they -- /// need to do anything after a process exec's itself. -- //------------------------------------------------------------------ -- virtual void -- DoDidExec () -- { -- } -- -- //------------------------------------------------------------------ -- /// Called before launching to a process. -- /// -- /// Allow Process plug-ins to execute some code before launching a -- /// process. -- /// -- /// @return -- /// Returns an error object. -- //------------------------------------------------------------------ -- virtual Error -- WillLaunch (Module* module) -- { -- return Error(); -- } -- -- //------------------------------------------------------------------ -- /// Launch a new process. -- /// -- /// Launch a new process by spawning a new process using \a module's -- /// file as the file to launch. Arguments are given in \a argv, -- /// and the environment variables are in \a envp. Standard input -- /// and output files can be optionally re-directed to \a stdin_path, -- /// \a stdout_path, and \a stderr_path. -- /// -- /// @param[in] module -- /// The module from which to extract the file specification and -- /// launch. -- /// -- /// @param[in] argv -- /// The argument array. -- /// -- /// @param[in] envp -- /// The environment array. -- /// -- /// @param[in] launch_flags -- /// Flags to modify the launch (@see lldb::LaunchFlags) -- /// -- /// @param[in] stdin_path -- /// The path to use when re-directing the STDIN of the new -- /// process. If all stdXX_path arguments are NULL, a pseudo -- /// terminal will be used. -- /// -- /// @param[in] stdout_path -- /// The path to use when re-directing the STDOUT of the new -- /// process. If all stdXX_path arguments are NULL, a pseudo -- /// terminal will be used. -- /// -- /// @param[in] stderr_path -- /// The path to use when re-directing the STDERR of the new -- /// process. If all stdXX_path arguments are NULL, a pseudo -- /// terminal will be used. -- /// -- /// @param[in] working_directory -- /// The working directory to have the child process run in -- /// -- /// @return -- /// A new valid process ID, or LLDB_INVALID_PROCESS_ID if -- /// launching fails. -- //------------------------------------------------------------------ -- virtual Error -- DoLaunch (Module *exe_module, -- const ProcessLaunchInfo &launch_info) -- { -- Error error; -- error.SetErrorStringWithFormat("error: %s does not support launching processes", GetPluginName().GetCString()); -- return error; -- } -- -- -- //------------------------------------------------------------------ -- /// Called after launching a process. -- /// -- /// Allow Process plug-ins to execute some code after launching -- /// a process. -- //------------------------------------------------------------------ -- virtual void -- DidLaunch () {} -- -- -- -- //------------------------------------------------------------------ -- /// Called before resuming to a process. -- /// -- /// Allow Process plug-ins to execute some code before resuming a -- /// process. -- /// -- /// @return -- /// Returns an error object. -- //------------------------------------------------------------------ -- virtual Error -- WillResume () { return Error(); } -- -- //------------------------------------------------------------------ -- /// Resumes all of a process's threads as configured using the -- /// Thread run control functions. -- /// -- /// Threads for a process should be updated with one of the run -- /// control actions (resume, step, or suspend) that they should take -- /// when the process is resumed. If no run control action is given -- /// to a thread it will be resumed by default. -- /// -- /// @return -- /// Returns \b true if the process successfully resumes using -- /// the thread run control actions, \b false otherwise. -- /// -- /// @see Thread:Resume() -- /// @see Thread:Step() -- /// @see Thread:Suspend() -- //------------------------------------------------------------------ -- virtual Error -- DoResume () -- { -- Error error; -- error.SetErrorStringWithFormat("error: %s does not support resuming processes", GetPluginName().GetCString()); -- return error; -- } -- -- -- //------------------------------------------------------------------ -- /// Called after resuming a process. -- /// -- /// Allow Process plug-ins to execute some code after resuming -- /// a process. -- //------------------------------------------------------------------ -- virtual void -- DidResume () {} -- -- -- //------------------------------------------------------------------ -- /// Called before halting to a process. -- /// -- /// Allow Process plug-ins to execute some code before halting a -- /// process. -- /// -- /// @return -- /// Returns an error object. -- //------------------------------------------------------------------ -- virtual Error -- WillHalt () { return Error(); } -- -- //------------------------------------------------------------------ -- /// Halts a running process. -- /// -- /// DoHalt must produce one and only one stop StateChanged event if it actually -- /// stops the process. If the stop happens through some natural event (for -- /// instance a SIGSTOP), then forwarding that event will do. Otherwise, you must -- /// generate the event manually. Note also, the private event thread is stopped when -- /// DoHalt is run to prevent the events generated while halting to trigger -- /// other state changes before the halt is complete. -- /// -- /// @param[out] caused_stop -- /// If true, then this Halt caused the stop, otherwise, the -- /// process was already stopped. -- /// -- /// @return -- /// Returns \b true if the process successfully halts, \b false -- /// otherwise. -- //------------------------------------------------------------------ -- virtual Error -- DoHalt (bool &caused_stop) -- { -- Error error; -- error.SetErrorStringWithFormat("error: %s does not support halting processes", GetPluginName().GetCString()); -- return error; -- } -- -- -- //------------------------------------------------------------------ -- /// Called after halting a process. -- /// -- /// Allow Process plug-ins to execute some code after halting -- /// a process. -- //------------------------------------------------------------------ -- virtual void -- DidHalt () {} -- -- //------------------------------------------------------------------ -- /// Called before detaching from a process. -- /// -- /// Allow Process plug-ins to execute some code before detaching -- /// from a process. -- /// -- /// @return -- /// Returns an error object. -- //------------------------------------------------------------------ -- virtual Error -- WillDetach () -- { -- return Error(); -- } -- -- //------------------------------------------------------------------ -- /// Detaches from a running or stopped process. -- /// -- /// @return -- /// Returns \b true if the process successfully detaches, \b -- /// false otherwise. -- //------------------------------------------------------------------ -- virtual Error -- DoDetach (bool keep_stopped) -- { -- Error error; -- error.SetErrorStringWithFormat("error: %s does not support detaching from processes", GetPluginName().GetCString()); -- return error; -- } -- -- -- //------------------------------------------------------------------ -- /// Called after detaching from a process. -- /// -- /// Allow Process plug-ins to execute some code after detaching -- /// from a process. -- //------------------------------------------------------------------ -- virtual void -- DidDetach () {} -- -- virtual bool -- DetachRequiresHalt() { return false; } -- -- //------------------------------------------------------------------ -- /// Called before sending a signal to a process. -- /// -- /// Allow Process plug-ins to execute some code before sending a -- /// signal to a process. -- /// -- /// @return -- /// Returns no error if it is safe to proceed with a call to -- /// Process::DoSignal(int), otherwise an error describing what -- /// prevents the signal from being sent. -- //------------------------------------------------------------------ -- virtual Error -- WillSignal () { return Error(); } -- -- //------------------------------------------------------------------ -- /// Sends a process a UNIX signal \a signal. -- /// -- /// @return -- /// Returns an error object. -- //------------------------------------------------------------------ -- virtual Error -- DoSignal (int signal) -- { -- Error error; -- error.SetErrorStringWithFormat("error: %s does not support senging signals to processes", GetPluginName().GetCString()); -- return error; -- } -- -- virtual Error -- WillDestroy () { return Error(); } -- -- virtual Error -- DoDestroy () = 0; -- -- virtual void -- DidDestroy () { } -- -- virtual bool -- DestroyRequiresHalt() { return true; } -- -- -- //------------------------------------------------------------------ -- /// Called after sending a signal to a process. -- /// -- /// Allow Process plug-ins to execute some code after sending a -- /// signal to a process. -- //------------------------------------------------------------------ -- virtual void -- DidSignal () {} -- -- //------------------------------------------------------------------ -- /// Currently called as part of ShouldStop. -- /// FIXME: Should really happen when the target stops before the -- /// event is taken from the queue... -- /// -- /// This callback is called as the event -- /// is about to be queued up to allow Process plug-ins to execute -- /// some code prior to clients being notified that a process was -- /// stopped. Common operations include updating the thread list, -- /// invalidating any thread state (registers, stack, etc) prior to -- /// letting the notification go out. -- /// -- //------------------------------------------------------------------ -- virtual void -- RefreshStateAfterStop () = 0; -- -- //------------------------------------------------------------------ -- /// Get the target object pointer for this module. -- /// -- /// @return -- /// A Target object pointer to the target that owns this -- /// module. -- //------------------------------------------------------------------ -- Target & -- GetTarget () -- { -- return m_target; -- } -- -- //------------------------------------------------------------------ -- /// Get the const target object pointer for this module. -- /// -- /// @return -- /// A const Target object pointer to the target that owns this -- /// module. -- //------------------------------------------------------------------ -- const Target & -- GetTarget () const -- { -- return m_target; -- } -- -- //------------------------------------------------------------------ -- /// Flush all data in the process. -- /// -- /// Flush the memory caches, all threads, and any other cached data -- /// in the process. -- /// -- /// This function can be called after a world changing event like -- /// adding a new symbol file, or after the process makes a large -- /// context switch (from boot ROM to booted into an OS). -- //------------------------------------------------------------------ -- void -- Flush (); -- -- //------------------------------------------------------------------ -- /// Get accessor for the current process state. -- /// -- /// @return -- /// The current state of the process. -- /// -- /// @see lldb::StateType -- //------------------------------------------------------------------ -- lldb::StateType -- GetState (); -- -- ExecutionResults -- RunThreadPlan (ExecutionContext &exe_ctx, -- lldb::ThreadPlanSP &thread_plan_sp, -- bool stop_others, -- bool run_others, -- bool unwind_on_error, -- bool ignore_breakpoints, -- uint32_t timeout_usec, -- Stream &errors); -- -- static const char * -- ExecutionResultAsCString (ExecutionResults result); -- -- void -- GetStatus (Stream &ostrm); -- -- size_t -- GetThreadStatus (Stream &ostrm, -- bool only_threads_with_stop_reason, -- uint32_t start_frame, -- uint32_t num_frames, -- uint32_t num_frames_with_source); -- -- void -- SendAsyncInterrupt (); -- --protected: -- -- void -- SetState (lldb::EventSP &event_sp); -- -- lldb::StateType -- GetPrivateState (); -- -- //------------------------------------------------------------------ -- /// The "private" side of resuming a process. This doesn't alter the -- /// state of m_run_lock, but just causes the process to resume. -- /// -- /// @return -- /// An Error object describing the success or failure of the resume. -- //------------------------------------------------------------------ -- Error -- PrivateResume (); -- -- //------------------------------------------------------------------ -- // Called internally -- //------------------------------------------------------------------ -- void -- CompleteAttach (); -- --public: -- //------------------------------------------------------------------ -- /// Get the exit status for a process. -- /// -- /// @return -- /// The process's return code, or -1 if the current process -- /// state is not eStateExited. -- //------------------------------------------------------------------ -- int -- GetExitStatus (); -- -- //------------------------------------------------------------------ -- /// Get a textual description of what the process exited. -- /// -- /// @return -- /// The textual description of why the process exited, or NULL -- /// if there is no description available. -- //------------------------------------------------------------------ -- const char * -- GetExitDescription (); -- -- -- virtual void -- DidExit () -- { -- } -- -- //------------------------------------------------------------------ -- /// Get the Modification ID of the process. -- /// -- /// @return -- /// The modification ID of the process. -- //------------------------------------------------------------------ -- ProcessModID -- GetModID () const -- { -- return m_mod_id; -- } -- -- const ProcessModID & -- GetModIDRef () const -- { -- return m_mod_id; -- } -- -- uint32_t -- GetStopID () const -- { -- return m_mod_id.GetStopID(); -- } -- -- uint32_t -- GetResumeID () const -- { -- return m_mod_id.GetResumeID(); -- } -- -- uint32_t -- GetLastUserExpressionResumeID () const -- { -- return m_mod_id.GetLastUserExpressionResumeID(); -- } -- -- uint32_t -- GetLastNaturalStopID() -- { -- return m_mod_id.GetLastNaturalStopID(); -- } -- -- //------------------------------------------------------------------ -- /// Set accessor for the process exit status (return code). -- /// -- /// Sometimes a child exits and the exit can be detected by global -- /// functions (signal handler for SIGCHLD for example). This -- /// accessor allows the exit status to be set from an external -- /// source. -- /// -- /// Setting this will cause a eStateExited event to be posted to -- /// the process event queue. -- /// -- /// @param[in] exit_status -- /// The value for the process's return code. -- /// -- /// @see lldb::StateType -- //------------------------------------------------------------------ -- virtual bool -- SetExitStatus (int exit_status, const char *cstr); -- -- //------------------------------------------------------------------ -- /// Check if a process is still alive. -- /// -- /// @return -- /// Returns \b true if the process is still valid, \b false -- /// otherwise. -- //------------------------------------------------------------------ -- virtual bool -- IsAlive () = 0; -- -- //------------------------------------------------------------------ -- /// Before lldb detaches from a process, it warns the user that they are about to lose their debug session. -- /// In some cases, this warning doesn't need to be emitted -- for instance, with core file debugging where -- /// the user can reconstruct the "state" by simply re-running the debugger on the core file. -- /// -- /// @return -- // true if the user should be warned about detaching from this process. -- //------------------------------------------------------------------ -- virtual bool -- WarnBeforeDetach () const -- { -- return true; -- } -- -- //------------------------------------------------------------------ -- /// Actually do the reading of memory from a process. -- /// -- /// Subclasses must override this function and can return fewer -- /// bytes than requested when memory requests are too large. This -- /// class will break up the memory requests and keep advancing the -- /// arguments along as needed. -- /// -- /// @param[in] vm_addr -- /// A virtual load address that indicates where to start reading -- /// memory from. -- /// -- /// @param[in] size -- /// The number of bytes to read. -- /// -- /// @param[out] buf -- /// A byte buffer that is at least \a size bytes long that -- /// will receive the memory bytes. -- /// -- /// @return -- /// The number of bytes that were actually read into \a buf. -- //------------------------------------------------------------------ -- virtual size_t -- DoReadMemory (lldb::addr_t vm_addr, -- void *buf, -- size_t size, -- Error &error) = 0; -- -- //------------------------------------------------------------------ -- /// Read of memory from a process. -- /// -- /// This function will read memory from the current process's -- /// address space and remove any traps that may have been inserted -- /// into the memory. -- /// -- /// This function is not meant to be overridden by Process -- /// subclasses, the subclasses should implement -- /// Process::DoReadMemory (lldb::addr_t, size_t, void *). -- /// -- /// @param[in] vm_addr -- /// A virtual load address that indicates where to start reading -- /// memory from. -- /// -- /// @param[out] buf -- /// A byte buffer that is at least \a size bytes long that -- /// will receive the memory bytes. -- /// -- /// @param[in] size -- /// The number of bytes to read. -- /// -- /// @return -- /// The number of bytes that were actually read into \a buf. If -- /// the returned number is greater than zero, yet less than \a -- /// size, then this function will get called again with \a -- /// vm_addr, \a buf, and \a size updated appropriately. Zero is -- /// returned to indicate an error. -- //------------------------------------------------------------------ -- virtual size_t -- ReadMemory (lldb::addr_t vm_addr, -- void *buf, -- size_t size, -- Error &error); -- -- //------------------------------------------------------------------ -- /// Read a NULL terminated string from memory -- /// -- /// This function will read a cache page at a time until a NULL -- /// string terminator is found. It will stop reading if an aligned -- /// sequence of NULL termination \a type_width bytes is not found -- /// before reading \a cstr_max_len bytes. The results are always -- /// guaranteed to be NULL terminated, and that no more than -- /// (max_bytes - type_width) bytes will be read. -- /// -- /// @param[in] vm_addr -- /// The virtual load address to start the memory read. -- /// -- /// @param[in] str -- /// A character buffer containing at least max_bytes. -- /// -- /// @param[in] max_bytes -- /// The maximum number of bytes to read. -- /// -- /// @param[in] error -- /// The error status of the read operation. -- /// -- /// @param[in] type_width -- /// The size of the null terminator (1 to 4 bytes per -- /// character). Defaults to 1. -- /// -- /// @return -- /// The error status or the number of bytes prior to the null terminator. -- //------------------------------------------------------------------ -- size_t -- ReadStringFromMemory (lldb::addr_t vm_addr, -- char *str, -- size_t max_bytes, -- Error &error, -- size_t type_width = 1); -- -- //------------------------------------------------------------------ -- /// Read a NULL terminated C string from memory -- /// -- /// This function will read a cache page at a time until the NULL -- /// C string terminator is found. It will stop reading if the NULL -- /// termination byte isn't found before reading \a cstr_max_len -- /// bytes, and the results are always guaranteed to be NULL -- /// terminated (at most cstr_max_len - 1 bytes will be read). -- //------------------------------------------------------------------ -- size_t -- ReadCStringFromMemory (lldb::addr_t vm_addr, -- char *cstr, -- size_t cstr_max_len, -- Error &error); -- -- size_t -- ReadCStringFromMemory (lldb::addr_t vm_addr, -- std::string &out_str, -- Error &error); -- -- size_t -- ReadMemoryFromInferior (lldb::addr_t vm_addr, -- void *buf, -- size_t size, -- Error &error); -- -- //------------------------------------------------------------------ -- /// Reads an unsigned integer of the specified byte size from -- /// process memory. -- /// -- /// @param[in] load_addr -- /// A load address of the integer to read. -- /// -- /// @param[in] byte_size -- /// The size in byte of the integer to read. -- /// -- /// @param[in] fail_value -- /// The value to return if we fail to read an integer. -- /// -- /// @param[out] error -- /// An error that indicates the success or failure of this -- /// operation. If error indicates success (error.Success()), -- /// then the value returned can be trusted, otherwise zero -- /// will be returned. -- /// -- /// @return -- /// The unsigned integer that was read from the process memory -- /// space. If the integer was smaller than a uint64_t, any -- /// unused upper bytes will be zero filled. If the process -- /// byte order differs from the host byte order, the integer -- /// value will be appropriately byte swapped into host byte -- /// order. -- //------------------------------------------------------------------ -- uint64_t -- ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr, -- size_t byte_size, -- uint64_t fail_value, -- Error &error); -- -- lldb::addr_t -- ReadPointerFromMemory (lldb::addr_t vm_addr, -- Error &error); -- -- bool -- WritePointerToMemory (lldb::addr_t vm_addr, -- lldb::addr_t ptr_value, -- Error &error); -- -- //------------------------------------------------------------------ -- /// Actually do the writing of memory to a process. -- /// -- /// @param[in] vm_addr -- /// A virtual load address that indicates where to start writing -- /// memory to. -- /// -- /// @param[in] buf -- /// A byte buffer that is at least \a size bytes long that -- /// contains the data to write. -- /// -- /// @param[in] size -- /// The number of bytes to write. -- /// -- /// @param[out] error -- /// An error value in case the memory write fails. -- /// -- /// @return -- /// The number of bytes that were actually written. -- //------------------------------------------------------------------ -- virtual size_t -- DoWriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error) -- { -- error.SetErrorStringWithFormat("error: %s does not support writing to processes", GetPluginName().GetCString()); -- return 0; -- } -- -- -- //------------------------------------------------------------------ -- /// Write all or part of a scalar value to memory. -- /// -- /// The value contained in \a scalar will be swapped to match the -- /// byte order of the process that is being debugged. If \a size is -- /// less than the size of scalar, the least significate \a size bytes -- /// from scalar will be written. If \a size is larger than the byte -- /// size of scalar, then the extra space will be padded with zeros -- /// and the scalar value will be placed in the least significant -- /// bytes in memory. -- /// -- /// @param[in] vm_addr -- /// A virtual load address that indicates where to start writing -- /// memory to. -- /// -- /// @param[in] scalar -- /// The scalar to write to the debugged process. -- /// -- /// @param[in] size -- /// This value can be smaller or larger than the scalar value -- /// itself. If \a size is smaller than the size of \a scalar, -- /// the least significant bytes in \a scalar will be used. If -- /// \a size is larger than the byte size of \a scalar, then -- /// the extra space will be padded with zeros. If \a size is -- /// set to UINT32_MAX, then the size of \a scalar will be used. -- /// -- /// @param[out] error -- /// An error value in case the memory write fails. -- /// -- /// @return -- /// The number of bytes that were actually written. -- //------------------------------------------------------------------ -- size_t -- WriteScalarToMemory (lldb::addr_t vm_addr, -- const Scalar &scalar, -- size_t size, -- Error &error); -- -- size_t -- ReadScalarIntegerFromMemory (lldb::addr_t addr, -- uint32_t byte_size, -- bool is_signed, -- Scalar &scalar, -- Error &error); -- -- //------------------------------------------------------------------ -- /// Write memory to a process. -- /// -- /// This function will write memory to the current process's -- /// address space and maintain any traps that might be present due -- /// to software breakpoints. -- /// -- /// This function is not meant to be overridden by Process -- /// subclasses, the subclasses should implement -- /// Process::DoWriteMemory (lldb::addr_t, size_t, void *). -- /// -- /// @param[in] vm_addr -- /// A virtual load address that indicates where to start writing -- /// memory to. -- /// -- /// @param[in] buf -- /// A byte buffer that is at least \a size bytes long that -- /// contains the data to write. -- /// -- /// @param[in] size -- /// The number of bytes to write. -- /// -- /// @return -- /// The number of bytes that were actually written. -- //------------------------------------------------------------------ -- size_t -- WriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error); -- -- -- //------------------------------------------------------------------ -- /// Actually allocate memory in the process. -- /// -- /// This function will allocate memory in the process's address -- /// space. This can't rely on the generic function calling mechanism, -- /// since that requires this function. -- /// -- /// @param[in] size -- /// The size of the allocation requested. -- /// -- /// @return -- /// The address of the allocated buffer in the process, or -- /// LLDB_INVALID_ADDRESS if the allocation failed. -- //------------------------------------------------------------------ -- -- virtual lldb::addr_t -- DoAllocateMemory (size_t size, uint32_t permissions, Error &error) -- { -- error.SetErrorStringWithFormat("error: %s does not support allocating in the debug process", GetPluginName().GetCString()); -- return LLDB_INVALID_ADDRESS; -- } -- -- -- //------------------------------------------------------------------ -- /// The public interface to allocating memory in the process. -- /// -- /// This function will allocate memory in the process's address -- /// space. This can't rely on the generic function calling mechanism, -- /// since that requires this function. -- /// -- /// @param[in] size -- /// The size of the allocation requested. -- /// -- /// @param[in] permissions -- /// Or together any of the lldb::Permissions bits. The permissions on -- /// a given memory allocation can't be changed after allocation. Note -- /// that a block that isn't set writable can still be written on from lldb, -- /// just not by the process itself. -- /// -- /// @param[in/out] error -- /// An error object to fill in if things go wrong. -- /// @return -- /// The address of the allocated buffer in the process, or -- /// LLDB_INVALID_ADDRESS if the allocation failed. -- //------------------------------------------------------------------ -- -- lldb::addr_t -- AllocateMemory (size_t size, uint32_t permissions, Error &error); -- -- -- //------------------------------------------------------------------ -- /// Resolve dynamically loaded indirect functions. -- /// -- /// @param[in] address -- /// The load address of the indirect function to resolve. -- /// -- /// @param[out] error -- /// An error value in case the resolve fails. -- /// -- /// @return -- /// The address of the resolved function. -- /// LLDB_INVALID_ADDRESS if the resolution failed. -- //------------------------------------------------------------------ -- -- virtual lldb::addr_t -- ResolveIndirectFunction(const Address *address, Error &error) -- { -- error.SetErrorStringWithFormat("error: %s does not support indirect functions in the debug process", GetPluginName().GetCString()); -- return LLDB_INVALID_ADDRESS; -- } -- -- virtual Error -- GetMemoryRegionInfo (lldb::addr_t load_addr, -- MemoryRegionInfo &range_info) -- { -- Error error; -- error.SetErrorString ("Process::GetMemoryRegionInfo() not supported"); -- return error; -- } -- -- virtual Error -- GetWatchpointSupportInfo (uint32_t &num) -- { -- Error error; -- num = 0; -- error.SetErrorString ("Process::GetWatchpointSupportInfo() not supported"); -- return error; -- } -- -- virtual Error -- GetWatchpointSupportInfo (uint32_t &num, bool& after) -- { -- Error error; -- num = 0; -- after = true; -- error.SetErrorString ("Process::GetWatchpointSupportInfo() not supported"); -- return error; -- } -- -- lldb::ModuleSP -- ReadModuleFromMemory (const FileSpec& file_spec, -- lldb::addr_t header_addr); -- -- //------------------------------------------------------------------ -- /// Attempt to get the attributes for a region of memory in the process. -- /// -- /// It may be possible for the remote debug server to inspect attributes -- /// for a region of memory in the process, such as whether there is a -- /// valid page of memory at a given address or whether that page is -- /// readable/writable/executable by the process. -- /// -- /// @param[in] load_addr -- /// The address of interest in the process. -- /// -- /// @param[out] permissions -- /// If this call returns successfully, this bitmask will have -- /// its Permissions bits set to indicate whether the region is -- /// readable/writable/executable. If this call fails, the -- /// bitmask values are undefined. -- /// -- /// @return -- /// Returns true if it was able to determine the attributes of the -- /// memory region. False if not. -- //------------------------------------------------------------------ -- -- virtual bool -- GetLoadAddressPermissions (lldb::addr_t load_addr, uint32_t &permissions) -- { -- MemoryRegionInfo range_info; -- permissions = 0; -- Error error (GetMemoryRegionInfo (load_addr, range_info)); -- if (!error.Success()) -- return false; -- if (range_info.GetReadable() == MemoryRegionInfo::eDontKnow -- || range_info.GetWritable() == MemoryRegionInfo::eDontKnow -- || range_info.GetExecutable() == MemoryRegionInfo::eDontKnow) -- { -- return false; -- } -- -- if (range_info.GetReadable() == MemoryRegionInfo::eYes) -- permissions |= lldb::ePermissionsReadable; -- -- if (range_info.GetWritable() == MemoryRegionInfo::eYes) -- permissions |= lldb::ePermissionsWritable; -- -- if (range_info.GetExecutable() == MemoryRegionInfo::eYes) -- permissions |= lldb::ePermissionsExecutable; -- -- return true; -- } -- -- //------------------------------------------------------------------ -- /// Determines whether executing JIT-compiled code in this process -- /// is possible. -- /// -- /// @return -- /// True if execution of JIT code is possible; false otherwise. -- //------------------------------------------------------------------ -- bool CanJIT (); -- -- //------------------------------------------------------------------ -- /// Sets whether executing JIT-compiled code in this process -- /// is possible. -- /// -- /// @param[in] can_jit -- /// True if execution of JIT code is possible; false otherwise. -- //------------------------------------------------------------------ -- void SetCanJIT (bool can_jit); -- -- //------------------------------------------------------------------ -- /// Actually deallocate memory in the process. -- /// -- /// This function will deallocate memory in the process's address -- /// space that was allocated with AllocateMemory. -- /// -- /// @param[in] ptr -- /// A return value from AllocateMemory, pointing to the memory you -- /// want to deallocate. -- /// -- /// @return -- /// \btrue if the memory was deallocated, \bfalse otherwise. -- //------------------------------------------------------------------ -- -- virtual Error -- DoDeallocateMemory (lldb::addr_t ptr) -- { -- Error error; -- error.SetErrorStringWithFormat("error: %s does not support deallocating in the debug process", GetPluginName().GetCString()); -- return error; -- } -- -- -- //------------------------------------------------------------------ -- /// The public interface to deallocating memory in the process. -- /// -- /// This function will deallocate memory in the process's address -- /// space that was allocated with AllocateMemory. -- /// -- /// @param[in] ptr -- /// A return value from AllocateMemory, pointing to the memory you -- /// want to deallocate. -- /// -- /// @return -- /// \btrue if the memory was deallocated, \bfalse otherwise. -- //------------------------------------------------------------------ -- -- Error -- DeallocateMemory (lldb::addr_t ptr); -- -- //------------------------------------------------------------------ -- /// Get any available STDOUT. -- /// -- /// If the process was launched without supplying valid file paths -- /// for stdin, stdout, and stderr, then the Process class might -- /// try to cache the STDOUT for the process if it is able. Events -- /// will be queued indicating that there is STDOUT available that -- /// can be retrieved using this function. -- /// -- /// @param[out] buf -- /// A buffer that will receive any STDOUT bytes that are -- /// currently available. -- /// -- /// @param[out] buf_size -- /// The size in bytes for the buffer \a buf. -- /// -- /// @return -- /// The number of bytes written into \a buf. If this value is -- /// equal to \a buf_size, another call to this function should -- /// be made to retrieve more STDOUT data. -- //------------------------------------------------------------------ -- virtual size_t -- GetSTDOUT (char *buf, size_t buf_size, Error &error); -- -- //------------------------------------------------------------------ -- /// Get any available STDERR. -- /// -- /// If the process was launched without supplying valid file paths -- /// for stdin, stdout, and stderr, then the Process class might -- /// try to cache the STDERR for the process if it is able. Events -- /// will be queued indicating that there is STDERR available that -- /// can be retrieved using this function. -- /// -- /// @param[out] buf -- /// A buffer that will receive any STDERR bytes that are -- /// currently available. -- /// -- /// @param[out] buf_size -- /// The size in bytes for the buffer \a buf. -- /// -- /// @return -- /// The number of bytes written into \a buf. If this value is -- /// equal to \a buf_size, another call to this function should -- /// be made to retrieve more STDERR data. -- //------------------------------------------------------------------ -- virtual size_t -- GetSTDERR (char *buf, size_t buf_size, Error &error); -- -- virtual size_t -- PutSTDIN (const char *buf, size_t buf_size, Error &error) -- { -- error.SetErrorString("stdin unsupported"); -- return 0; -- } -- -- //------------------------------------------------------------------ -- /// Get any available profile data. -- /// -- /// @param[out] buf -- /// A buffer that will receive any profile data bytes that are -- /// currently available. -- /// -- /// @param[out] buf_size -- /// The size in bytes for the buffer \a buf. -- /// -- /// @return -- /// The number of bytes written into \a buf. If this value is -- /// equal to \a buf_size, another call to this function should -- /// be made to retrieve more profile data. -- //------------------------------------------------------------------ -- virtual size_t -- GetAsyncProfileData (char *buf, size_t buf_size, Error &error); -- -- //---------------------------------------------------------------------- -- // Process Breakpoints -- //---------------------------------------------------------------------- -- size_t -- GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site); -- -- virtual Error -- EnableBreakpointSite (BreakpointSite *bp_site) -- { -- Error error; -- error.SetErrorStringWithFormat("error: %s does not support enabling breakpoints", GetPluginName().GetCString()); -- return error; -- } -- -- -- virtual Error -- DisableBreakpointSite (BreakpointSite *bp_site) -- { -- Error error; -- error.SetErrorStringWithFormat("error: %s does not support disabling breakpoints", GetPluginName().GetCString()); -- return error; -- } -- -- -- // This is implemented completely using the lldb::Process API. Subclasses -- // don't need to implement this function unless the standard flow of -- // read existing opcode, write breakpoint opcode, verify breakpoint opcode -- // doesn't work for a specific process plug-in. -- virtual Error -- EnableSoftwareBreakpoint (BreakpointSite *bp_site); -- -- // This is implemented completely using the lldb::Process API. Subclasses -- // don't need to implement this function unless the standard flow of -- // restoring original opcode in memory and verifying the restored opcode -- // doesn't work for a specific process plug-in. -- virtual Error -- DisableSoftwareBreakpoint (BreakpointSite *bp_site); -- -- BreakpointSiteList & -- GetBreakpointSiteList(); -- -- const BreakpointSiteList & -- GetBreakpointSiteList() const; -- -- void -- DisableAllBreakpointSites (); -- -- Error -- ClearBreakpointSiteByID (lldb::user_id_t break_id); -- -- lldb::break_id_t -- CreateBreakpointSite (const lldb::BreakpointLocationSP &owner, -- bool use_hardware); -- -- Error -- DisableBreakpointSiteByID (lldb::user_id_t break_id); -- -- Error -- EnableBreakpointSiteByID (lldb::user_id_t break_id); -- -- -- // BreakpointLocations use RemoveOwnerFromBreakpointSite to remove -- // themselves from the owner's list of this breakpoint sites. -- void -- RemoveOwnerFromBreakpointSite (lldb::user_id_t owner_id, -- lldb::user_id_t owner_loc_id, -- lldb::BreakpointSiteSP &bp_site_sp); -- -- //---------------------------------------------------------------------- -- // Process Watchpoints (optional) -- //---------------------------------------------------------------------- -- virtual Error -- EnableWatchpoint (Watchpoint *wp, bool notify = true); -- -- virtual Error -- DisableWatchpoint (Watchpoint *wp, bool notify = true); -- -- //------------------------------------------------------------------ -- // Thread Queries -- //------------------------------------------------------------------ -- virtual bool -- UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list) = 0; -- -- void -- UpdateThreadListIfNeeded (); -- -- ThreadList & -- GetThreadList () -- { -- return m_thread_list; -- } -- -- // This is obsoleted and will be removed very soon. -- uint32_t -- GetNextThreadIndexID (); -- -- uint32_t -- GetNextThreadIndexID (uint64_t thread_id); -- -- lldb::ThreadSP -- CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context); -- -- // Returns true if an index id has been assigned to a thread. -- bool -- HasAssignedIndexIDToThread(uint64_t sb_thread_id); -- -- // Given a thread_id, it will assign a more reasonable index id for display to the user. -- // If the thread_id has previously been assigned, the same index id will be used. -- uint32_t -- AssignIndexIDToThread(uint64_t thread_id); -- -- //------------------------------------------------------------------ -- // Event Handling -- //------------------------------------------------------------------ -- lldb::StateType -- GetNextEvent (lldb::EventSP &event_sp); -- -- lldb::StateType -- WaitForProcessToStop (const TimeValue *timeout, lldb::EventSP *event_sp_ptr = NULL); -- -- lldb::StateType -- WaitForStateChangedEvents (const TimeValue *timeout, lldb::EventSP &event_sp); -- -- Event * -- PeekAtStateChangedEvents (); -- -- -- class -- ProcessEventHijacker -- { -- public: -- ProcessEventHijacker (Process &process, Listener *listener) : -- m_process (process) -- { -- m_process.HijackProcessEvents (listener); -- } -- ~ProcessEventHijacker () -- { -- m_process.RestoreProcessEvents(); -- } -- -- private: -- Process &m_process; -- }; -- friend class ProcessEventHijacker; -- //------------------------------------------------------------------ -- /// If you need to ensure that you and only you will hear about some public -- /// event, then make a new listener, set to listen to process events, and -- /// then call this with that listener. Then you will have to wait on that -- /// listener explicitly for events (rather than using the GetNextEvent & WaitFor* -- /// calls above. Be sure to call RestoreProcessEvents when you are done. -- /// -- /// @param[in] listener -- /// This is the new listener to whom all process events will be delivered. -- /// -- /// @return -- /// Returns \b true if the new listener could be installed, -- /// \b false otherwise. -- //------------------------------------------------------------------ -- bool -- HijackProcessEvents (Listener *listener); -- -- //------------------------------------------------------------------ -- /// Restores the process event broadcasting to its normal state. -- /// -- //------------------------------------------------------------------ -- void -- RestoreProcessEvents (); -- --private: -- //------------------------------------------------------------------ -- /// This is the part of the event handling that for a process event. -- /// It decides what to do with the event and returns true if the -- /// event needs to be propagated to the user, and false otherwise. -- /// If the event is not propagated, this call will most likely set -- /// the target to executing again. -- /// There is only one place where this call should be called, HandlePrivateEvent. -- /// Don't call it from anywhere else... -- /// -- /// @param[in] event_ptr -- /// This is the event we are handling. -- /// -- /// @return -- /// Returns \b true if the event should be reported to the -- /// user, \b false otherwise. -- //------------------------------------------------------------------ -- bool -- ShouldBroadcastEvent (Event *event_ptr); -- --public: -- const lldb::ABISP & -- GetABI (); -- -- OperatingSystem * -- GetOperatingSystem () -- { -- return m_os_ap.get(); -- } -- -- -- virtual LanguageRuntime * -- GetLanguageRuntime (lldb::LanguageType language, bool retry_if_null = true); -- -- virtual CPPLanguageRuntime * -- GetCPPLanguageRuntime (bool retry_if_null = true); -- -- virtual ObjCLanguageRuntime * -- GetObjCLanguageRuntime (bool retry_if_null = true); -- -- bool -- IsPossibleDynamicValue (ValueObject& in_value); -- -- bool -- IsRunning () const; -- -- DynamicCheckerFunctions *GetDynamicCheckers() -- { -- return m_dynamic_checkers_ap.get(); -- } -- -- void SetDynamicCheckers(DynamicCheckerFunctions *dynamic_checkers) -- { -- m_dynamic_checkers_ap.reset(dynamic_checkers); -- } -- -- //------------------------------------------------------------------ -- /// Call this to set the lldb in the mode where it breaks on new thread -- /// creations, and then auto-restarts. This is useful when you are trying -- /// to run only one thread, but either that thread or the kernel is creating -- /// new threads in the process. If you stop when the thread is created, you -- /// can immediately suspend it, and keep executing only the one thread you intend. -- /// -- /// @return -- /// Returns \b true if we were able to start up the notification -- /// \b false otherwise. -- //------------------------------------------------------------------ -- virtual bool -- StartNoticingNewThreads() -- { -- return true; -- } -- -- //------------------------------------------------------------------ -- /// Call this to turn off the stop & notice new threads mode. -- /// -- /// @return -- /// Returns \b true if we were able to start up the notification -- /// \b false otherwise. -- //------------------------------------------------------------------ -- virtual bool -- StopNoticingNewThreads() -- { -- return true; -- } -- -- void -- SetRunningUserExpression (bool on); -- -- //------------------------------------------------------------------ -- // lldb::ExecutionContextScope pure virtual functions -- //------------------------------------------------------------------ -- virtual lldb::TargetSP -- CalculateTarget (); -- -- virtual lldb::ProcessSP -- CalculateProcess () -- { -- return shared_from_this(); -- } -- -- virtual lldb::ThreadSP -- CalculateThread () -- { -- return lldb::ThreadSP(); -- } -- -- virtual lldb::StackFrameSP -- CalculateStackFrame () -- { -- return lldb::StackFrameSP(); -- } -- -- virtual void -- CalculateExecutionContext (ExecutionContext &exe_ctx); -- -- void -- SetSTDIOFileDescriptor (int file_descriptor); -- -- //------------------------------------------------------------------ -- // Add a permanent region of memory that should never be read or -- // written to. This can be used to ensure that memory reads or writes -- // to certain areas of memory never end up being sent to the -- // DoReadMemory or DoWriteMemory functions which can improve -- // performance. -- //------------------------------------------------------------------ -- void -- AddInvalidMemoryRegion (const LoadRange ®ion); -- -- //------------------------------------------------------------------ -- // Remove a permanent region of memory that should never be read or -- // written to that was previously added with AddInvalidMemoryRegion. -- //------------------------------------------------------------------ -- bool -- RemoveInvalidMemoryRange (const LoadRange ®ion); -- -- //------------------------------------------------------------------ -- // If the setup code of a thread plan needs to do work that might involve -- // calling a function in the target, it should not do that work directly -- // in one of the thread plan functions (DidPush/WillResume) because -- // such work needs to be handled carefully. Instead, put that work in -- // a PreResumeAction callback, and register it with the process. It will -- // get done before the actual "DoResume" gets called. -- //------------------------------------------------------------------ -- -- typedef bool (PreResumeActionCallback)(void *); -- -- void -- AddPreResumeAction (PreResumeActionCallback callback, void *baton); -- -- bool -- RunPreResumeActions (); -- -- void -- ClearPreResumeActions (); -- -- ReadWriteLock & -- GetRunLock () -- { -- // The "m_private_run_lock" causes problems for other platforms -- // right now, so we are leaving this in for Apple builds only -- // until we can get the kinks worked out. -- if (Host::GetCurrentThread() == m_private_state_thread) -- return m_private_run_lock; -- else -- return m_public_run_lock; -- } -- -- //------------------------------------------------------------------ -- // This is a cache of reserved and available memory address ranges -- // for a single modification ID (see m_mod_id). It's meant for use -- // by IRMemoryMap, but to stick with the process. These memory -- // ranges happen to be unallocated in the underlying process, but we -- // make no guarantee that at a future modification ID they won't be -- // gone. This is only useful if the underlying process can't -- // allocate memory. -- // -- // When a memory space is determined to be available it is -- // registered as reserved at the current modification. If it is -- // freed later, it is added to the free list if the modification ID -- // hasn't changed. Then clients can simply query the free list for -- // the size they want. -- //------------------------------------------------------------------ -- class ReservationCache -- { -- public: -- ReservationCache (Process &process); -- -- //------------------------------------------------------------------ -- // Mark that a particular range of addresses is in use. Adds it -- // to the reserved map, implicitly tying it to the current -- // modification ID. -- //------------------------------------------------------------------ -- void -- Reserve (lldb::addr_t addr, size_t size); -- -- //------------------------------------------------------------------ -- // Mark that a range is no longer in use. If it's found in the -- // reservation list, that means that the modification ID hasn't -- // changed since it was reserved, so it can be safely added to the -- // free list. -- //------------------------------------------------------------------ -- void -- Unreserve (lldb::addr_t addr); -- -- //------------------------------------------------------------------ -- // Try to find an unused range of the given size in the free list. -- //------------------------------------------------------------------ -- lldb::addr_t -- Find (size_t size); -- private: -- //------------------------------------------------------------------ -- // Clear all lists if the modification ID has changed. -- //------------------------------------------------------------------ -- void CheckModID(); -- -- typedef std::map ReservedMap; -- typedef std::vector FreeList; -- typedef std::map FreeMap; -- -- ReservedMap m_reserved_cache; -- FreeMap m_free_cache; -- -- Process &m_process; -- ProcessModID m_mod_id; -- }; -- -- ReservationCache & -- GetReservationCache () -- { -- return m_reservation_cache; -- } --private: -- ReservationCache m_reservation_cache; --protected: -- //------------------------------------------------------------------ -- // NextEventAction provides a way to register an action on the next -- // event that is delivered to this process. There is currently only -- // one next event action allowed in the process at one time. If a -- // new "NextEventAction" is added while one is already present, the -- // old action will be discarded (with HandleBeingUnshipped called -- // after it is discarded.) -- // -- // If you want to resume the process as a result of a resume action, -- // call RequestResume, don't call Resume directly. -- //------------------------------------------------------------------ -- class NextEventAction -- { -- public: -- typedef enum EventActionResult -- { -- eEventActionSuccess, -- eEventActionRetry, -- eEventActionExit -- } EventActionResult; -- -- NextEventAction (Process *process) : -- m_process(process) -- { -- } -- -- virtual -- ~NextEventAction() -- { -- } -- -- virtual EventActionResult PerformAction (lldb::EventSP &event_sp) = 0; -- virtual void HandleBeingUnshipped () {} -- virtual EventActionResult HandleBeingInterrupted () = 0; -- virtual const char *GetExitString() = 0; -- void RequestResume() -- { -- m_process->m_resume_requested = true; -- } -- protected: -- Process *m_process; -- }; -- -- void SetNextEventAction (Process::NextEventAction *next_event_action) -- { -- if (m_next_event_action_ap.get()) -- m_next_event_action_ap->HandleBeingUnshipped(); -- -- m_next_event_action_ap.reset(next_event_action); -- } -- -- // This is the completer for Attaching: -- class AttachCompletionHandler : public NextEventAction -- { -- public: -- AttachCompletionHandler (Process *process, uint32_t exec_count) : -- NextEventAction (process), -- m_exec_count (exec_count) -- { -- } -- -- virtual -- ~AttachCompletionHandler() -- { -- } -- -- virtual EventActionResult PerformAction (lldb::EventSP &event_sp); -- virtual EventActionResult HandleBeingInterrupted (); -- virtual const char *GetExitString(); -- private: -- uint32_t m_exec_count; -- std::string m_exit_string; -- }; -- -- bool -- HijackPrivateProcessEvents (Listener *listener); -- -- void -- RestorePrivateProcessEvents (); -- -- bool -- PrivateStateThreadIsValid () const -- { -- return IS_VALID_LLDB_HOST_THREAD(m_private_state_thread); -- } -- -- //------------------------------------------------------------------ -- // Type definitions -- //------------------------------------------------------------------ -- typedef std::map LanguageRuntimeCollection; -- -- struct PreResumeCallbackAndBaton -- { -- bool (*callback) (void *); -- void *baton; -- PreResumeCallbackAndBaton (PreResumeActionCallback in_callback, void *in_baton) : -- callback (in_callback), -- baton (in_baton) -- { -- } -- }; -- -- //------------------------------------------------------------------ -- // Member variables -- //------------------------------------------------------------------ -- Target & m_target; ///< The target that owns this process. -- ThreadSafeValue m_public_state; -- ThreadSafeValue m_private_state; // The actual state of our process -- Broadcaster m_private_state_broadcaster; // This broadcaster feeds state changed events into the private state thread's listener. -- Broadcaster m_private_state_control_broadcaster; // This is the control broadcaster, used to pause, resume & stop the private state thread. -- Listener m_private_state_listener; // This is the listener for the private state thread. -- Predicate m_private_state_control_wait; /// This Predicate is used to signal that a control operation is complete. -- lldb::thread_t m_private_state_thread; // Thread ID for the thread that watches interal state events -- ProcessModID m_mod_id; ///< Tracks the state of the process over stops and other alterations. -- uint32_t m_process_unique_id; ///< Each lldb_private::Process class that is created gets a unique integer ID that increments with each new instance -- uint32_t m_thread_index_id; ///< Each thread is created with a 1 based index that won't get re-used. -- std::map m_thread_id_to_index_id_map; -- int m_exit_status; ///< The exit status of the process, or -1 if not set. -- std::string m_exit_string; ///< A textual description of why a process exited. -- Mutex m_thread_mutex; -- ThreadList m_thread_list_real; ///< The threads for this process as are known to the protocol we are debugging with -- ThreadList m_thread_list; ///< The threads for this process as the user will see them. This is usually the same as -- ///< m_thread_list_real, but might be different if there is an OS plug-in creating memory threads -- std::vector m_notifications; ///< The list of notifications that this process can deliver. -- std::vector m_image_tokens; -- Listener &m_listener; -- BreakpointSiteList m_breakpoint_site_list; ///< This is the list of breakpoint locations we intend to insert in the target. -- std::unique_ptr m_dyld_ap; -- std::unique_ptr m_dynamic_checkers_ap; ///< The functions used by the expression parser to validate data that expressions use. -- std::unique_ptr m_os_ap; -- UnixSignals m_unix_signals; /// This is the current signal set for this process. -- lldb::ABISP m_abi_sp; -- lldb::InputReaderSP m_process_input_reader; -- Communication m_stdio_communication; -- Mutex m_stdio_communication_mutex; -- std::string m_stdout_data; -- std::string m_stderr_data; -- Mutex m_profile_data_comm_mutex; -- std::vector m_profile_data; -- MemoryCache m_memory_cache; -- AllocatedMemoryCache m_allocated_memory_cache; -- bool m_should_detach; /// Should we detach if the process object goes away with an explicit call to Kill or Detach? -- LanguageRuntimeCollection m_language_runtimes; -- std::unique_ptr m_next_event_action_ap; -- std::vector m_pre_resume_actions; -- ReadWriteLock m_public_run_lock; -- ReadWriteLock m_private_run_lock; -- Predicate m_currently_handling_event; // This predicate is set in HandlePrivateEvent while all its business is being done. -- bool m_currently_handling_do_on_removals; -- bool m_resume_requested; // If m_currently_handling_event or m_currently_handling_do_on_removals are true, Resume will only request a resume, using this flag to check. -- bool m_finalize_called; -- bool m_clear_thread_plans_on_stop; -- lldb::StateType m_last_broadcast_state; /// This helps with the Public event coalescing in ShouldBroadcastEvent. -- bool m_destroy_in_process; -- -- enum { -- eCanJITDontKnow= 0, -- eCanJITYes, -- eCanJITNo -- } m_can_jit; -- -- size_t -- RemoveBreakpointOpcodesFromBuffer (lldb::addr_t addr, size_t size, uint8_t *buf) const; -- -- void -- SynchronouslyNotifyStateChanged (lldb::StateType state); -- -- void -- SetPublicState (lldb::StateType new_state, bool restarted); -- -- void -- SetPrivateState (lldb::StateType state); -- -- bool -- StartPrivateStateThread (bool force = false); -- -- void -- StopPrivateStateThread (); -- -- void -- PausePrivateStateThread (); -- -- void -- ResumePrivateStateThread (); -- -- static void * -- PrivateStateThread (void *arg); -- -- void * -- RunPrivateStateThread (); -- -- void -- HandlePrivateEvent (lldb::EventSP &event_sp); -- -- lldb::StateType -- WaitForProcessStopPrivate (const TimeValue *timeout, lldb::EventSP &event_sp); -- -- // This waits for both the state change broadcaster, and the control broadcaster. -- // If control_only, it only waits for the control broadcaster. -- -- bool -- WaitForEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp, bool control_only); -- -- lldb::StateType -- WaitForStateChangedEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp); -- -- lldb::StateType -- WaitForState (const TimeValue *timeout, -- const lldb::StateType *match_states, -- const uint32_t num_match_states); -- -- size_t -- WriteMemoryPrivate (lldb::addr_t addr, const void *buf, size_t size, Error &error); -- -- void -- AppendSTDOUT (const char *s, size_t len); -- -- void -- AppendSTDERR (const char *s, size_t len); -- -- void -- BroadcastAsyncProfileData(const char *s, size_t len); -- -- static void -- STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len); -- -- void -- PushProcessInputReader (); -- -- void -- PopProcessInputReader (); -- -- void -- ResetProcessInputReader (); -- -- static size_t -- ProcessInputReaderCallback (void *baton, -- InputReader &reader, -- lldb::InputReaderAction notification, -- const char *bytes, -- size_t bytes_len); -- -- Error -- HaltForDestroyOrDetach(lldb::EventSP &exit_event_sp); -- --private: -- //------------------------------------------------------------------ -- // For Process only -- //------------------------------------------------------------------ -- void ControlPrivateStateThread (uint32_t signal); -- -- DISALLOW_COPY_AND_ASSIGN (Process); -- --}; -- --} // namespace lldb_private -- --#endif // liblldb_Process_h_ diff --git a/debian/patches/lldb-hurd.diff b/debian/patches/lldb-hurd.diff index 2841f193..e5d2d262 100644 --- a/debian/patches/lldb-hurd.diff +++ b/debian/patches/lldb-hurd.diff @@ -11,1526 +11,6 @@ Index: llvm-toolchain-3.3-3.3/lldb/include/lldb/Host/Config.h #include "lldb/Host/linux/Config.h" -Index: llvm-toolchain-3.3-3.3/home/sylvestre/llvm-toolchain-3.3-3.3/tools/lldb/source/Host/common/Host.cpp -=================================================================== ---- llvm-toolchain-3.3-3.3.orig/home/sylvestre/llvm-toolchain-3.3-3.3/tools/lldb/source/Host/common/Host.cpp 2013-08-28 10:29:30.000000000 +0000 -+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 -@@ -1,1515 +0,0 @@ --//===-- Host.cpp ------------------------------------------------*- C++ -*-===// --// --// The LLVM Compiler Infrastructure --// --// This file is distributed under the University of Illinois Open Source --// License. See LICENSE.TXT for details. --// --//===----------------------------------------------------------------------===// -- --#include "lldb/lldb-python.h" -- --// C includes --#include --#include --#include --#include --#include --#include --#include --#include --#include -- --#if defined (__APPLE__) -- --#include --#include --#include --#include -- --#elif defined (__linux__) || defined(__FreeBSD_kernel__) --/* Linux or the FreeBSD kernel with glibc (Debian KFreeBSD for example) */ -- --#include -- --#elif defined (__FreeBSD__) -- --#include --#include -- --#endif -- --#include "lldb/Host/Host.h" --#include "lldb/Core/ArchSpec.h" --#include "lldb/Core/ConstString.h" --#include "lldb/Core/Debugger.h" --#include "lldb/Core/Error.h" --#include "lldb/Core/Log.h" --#include "lldb/Core/StreamString.h" --#include "lldb/Core/ThreadSafeSTLMap.h" --#include "lldb/Host/Config.h" --#include "lldb/Host/Endian.h" --#include "lldb/Host/FileSpec.h" --#include "lldb/Host/Mutex.h" --#include "lldb/Target/Process.h" --#include "lldb/Target/TargetList.h" -- --#include "llvm/Support/Host.h" --#include "llvm/Support/MachO.h" --#include "llvm/ADT/Twine.h" -- -- -- -- -- --using namespace lldb; --using namespace lldb_private; -- -- --#if !defined (__APPLE__) --struct MonitorInfo --{ -- lldb::pid_t pid; // The process ID to monitor -- Host::MonitorChildProcessCallback callback; // The callback function to call when "pid" exits or signals -- void *callback_baton; // The callback baton for the callback function -- bool monitor_signals; // If true, call the callback when "pid" gets signaled. --}; -- --static void * --MonitorChildProcessThreadFunction (void *arg); -- --lldb::thread_t --Host::StartMonitoringChildProcess --( -- Host::MonitorChildProcessCallback callback, -- void *callback_baton, -- lldb::pid_t pid, -- bool monitor_signals --) --{ -- lldb::thread_t thread = LLDB_INVALID_HOST_THREAD; -- MonitorInfo * info_ptr = new MonitorInfo(); -- -- info_ptr->pid = pid; -- info_ptr->callback = callback; -- info_ptr->callback_baton = callback_baton; -- info_ptr->monitor_signals = monitor_signals; -- -- char thread_name[256]; -- ::snprintf (thread_name, sizeof(thread_name), "", pid); -- thread = ThreadCreate (thread_name, -- MonitorChildProcessThreadFunction, -- info_ptr, -- NULL); -- -- return thread; --} -- --//------------------------------------------------------------------ --// Scoped class that will disable thread canceling when it is --// constructed, and exception safely restore the previous value it --// when it goes out of scope. --//------------------------------------------------------------------ --class ScopedPThreadCancelDisabler --{ --public: -- ScopedPThreadCancelDisabler() -- { -- // Disable the ability for this thread to be cancelled -- int err = ::pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &m_old_state); -- if (err != 0) -- m_old_state = -1; -- -- } -- -- ~ScopedPThreadCancelDisabler() -- { -- // Restore the ability for this thread to be cancelled to what it -- // previously was. -- if (m_old_state != -1) -- ::pthread_setcancelstate (m_old_state, 0); -- } --private: -- int m_old_state; // Save the old cancelability state. --}; -- --static void * --MonitorChildProcessThreadFunction (void *arg) --{ -- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); -- const char *function = __FUNCTION__; -- if (log) -- log->Printf ("%s (arg = %p) thread starting...", function, arg); -- -- MonitorInfo *info = (MonitorInfo *)arg; -- -- const Host::MonitorChildProcessCallback callback = info->callback; -- void * const callback_baton = info->callback_baton; -- const lldb::pid_t pid = info->pid; -- const bool monitor_signals = info->monitor_signals; -- -- delete info; -- -- int status = -1; --#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) -- #define __WALL 0 --#endif -- const int options = __WALL; -- -- while (1) -- { -- log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS); -- if (log) -- log->Printf("%s ::wait_pid (pid = %" PRIu64 ", &status, options = %i)...", function, pid, options); -- -- // Wait for all child processes -- ::pthread_testcancel (); -- // Get signals from all children with same process group of pid -- const lldb::pid_t wait_pid = ::waitpid (-1*pid, &status, options); -- ::pthread_testcancel (); -- -- if (wait_pid == -1) -- { -- if (errno == EINTR) -- continue; -- else -- { -- if (log) -- log->Printf ("%s (arg = %p) thread exiting because waitpid failed (%s)...", __FUNCTION__, arg, strerror(errno)); -- break; -- } -- } -- else if (wait_pid > 0) -- { -- bool exited = false; -- int signal = 0; -- int exit_status = 0; -- const char *status_cstr = NULL; -- if (WIFSTOPPED(status)) -- { -- signal = WSTOPSIG(status); -- status_cstr = "STOPPED"; -- } -- else if (WIFEXITED(status)) -- { -- exit_status = WEXITSTATUS(status); -- status_cstr = "EXITED"; -- exited = true; -- } -- else if (WIFSIGNALED(status)) -- { -- signal = WTERMSIG(status); -- status_cstr = "SIGNALED"; -- if (wait_pid == pid) { -- exited = true; -- exit_status = -1; -- } -- } -- else -- { -- status_cstr = "(\?\?\?)"; -- } -- -- // Scope for pthread_cancel_disabler -- { -- ScopedPThreadCancelDisabler pthread_cancel_disabler; -- -- log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS); -- if (log) -- log->Printf ("%s ::waitpid (pid = %" PRIu64 ", &status, options = %i) => pid = %" PRIu64 ", status = 0x%8.8x (%s), signal = %i, exit_state = %i", -- function, -- wait_pid, -- options, -- pid, -- status, -- status_cstr, -- signal, -- exit_status); -- -- if (exited || (signal != 0 && monitor_signals)) -- { -- bool callback_return = false; -- if (callback) -- callback_return = callback (callback_baton, wait_pid, exited, signal, exit_status); -- -- // If our process exited, then this thread should exit -- if (exited && wait_pid == pid) -- { -- if (log) -- log->Printf ("%s (arg = %p) thread exiting because pid received exit signal...", __FUNCTION__, arg); -- break; -- } -- // If the callback returns true, it means this process should -- // exit -- if (callback_return) -- { -- if (log) -- log->Printf ("%s (arg = %p) thread exiting because callback returned true...", __FUNCTION__, arg); -- break; -- } -- } -- } -- } -- } -- -- log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS); -- if (log) -- log->Printf ("%s (arg = %p) thread exiting...", __FUNCTION__, arg); -- -- return NULL; --} -- -- --void --Host::SystemLog (SystemLogType type, const char *format, va_list args) --{ -- vfprintf (stderr, format, args); --} -- --#endif // #if !defined (__APPLE__) -- --void --Host::SystemLog (SystemLogType type, const char *format, ...) --{ -- va_list args; -- va_start (args, format); -- SystemLog (type, format, args); -- va_end (args); --} -- --size_t --Host::GetPageSize() --{ -- return ::getpagesize(); --} -- --const ArchSpec & --Host::GetArchitecture (SystemDefaultArchitecture arch_kind) --{ -- static bool g_supports_32 = false; -- static bool g_supports_64 = false; -- static ArchSpec g_host_arch_32; -- static ArchSpec g_host_arch_64; -- --#if defined (__APPLE__) -- -- // Apple is different in that it can support both 32 and 64 bit executables -- // in the same operating system running concurrently. Here we detect the -- // correct host architectures for both 32 and 64 bit including if 64 bit -- // executables are supported on the system. -- -- if (g_supports_32 == false && g_supports_64 == false) -- { -- // All apple systems support 32 bit execution. -- g_supports_32 = true; -- uint32_t cputype, cpusubtype; -- uint32_t is_64_bit_capable = false; -- size_t len = sizeof(cputype); -- ArchSpec host_arch; -- // These will tell us about the kernel architecture, which even on a 64 -- // bit machine can be 32 bit... -- if (::sysctlbyname("hw.cputype", &cputype, &len, NULL, 0) == 0) -- { -- len = sizeof (cpusubtype); -- if (::sysctlbyname("hw.cpusubtype", &cpusubtype, &len, NULL, 0) != 0) -- cpusubtype = CPU_TYPE_ANY; -- -- len = sizeof (is_64_bit_capable); -- if (::sysctlbyname("hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0) == 0) -- { -- if (is_64_bit_capable) -- g_supports_64 = true; -- } -- -- if (is_64_bit_capable) -- { --#if defined (__i386__) || defined (__x86_64__) -- if (cpusubtype == CPU_SUBTYPE_486) -- cpusubtype = CPU_SUBTYPE_I386_ALL; --#endif -- if (cputype & CPU_ARCH_ABI64) -- { -- // We have a 64 bit kernel on a 64 bit system -- g_host_arch_32.SetArchitecture (eArchTypeMachO, ~(CPU_ARCH_MASK) & cputype, cpusubtype); -- g_host_arch_64.SetArchitecture (eArchTypeMachO, cputype, cpusubtype); -- } -- else -- { -- // We have a 32 bit kernel on a 64 bit system -- g_host_arch_32.SetArchitecture (eArchTypeMachO, cputype, cpusubtype); -- cputype |= CPU_ARCH_ABI64; -- g_host_arch_64.SetArchitecture (eArchTypeMachO, cputype, cpusubtype); -- } -- } -- else -- { -- g_host_arch_32.SetArchitecture (eArchTypeMachO, cputype, cpusubtype); -- g_host_arch_64.Clear(); -- } -- } -- } -- --#else // #if defined (__APPLE__) -- -- if (g_supports_32 == false && g_supports_64 == false) -- { -- llvm::Triple triple(llvm::sys::getDefaultTargetTriple()); -- -- g_host_arch_32.Clear(); -- g_host_arch_64.Clear(); -- -- // If the OS is Linux, "unknown" in the vendor slot isn't what we want -- // for the default triple. It's probably an artifact of config.guess. -- if (triple.getOS() == llvm::Triple::Linux && triple.getVendor() == llvm::Triple::UnknownVendor) -- triple.setVendorName(""); -- -- switch (triple.getArch()) -- { -- default: -- g_host_arch_32.SetTriple(triple); -- g_supports_32 = true; -- break; -- -- case llvm::Triple::x86_64: -- g_host_arch_64.SetTriple(triple); -- g_supports_64 = true; -- g_host_arch_32.SetTriple(triple.get32BitArchVariant()); -- g_supports_32 = true; -- break; -- -- case llvm::Triple::sparcv9: -- case llvm::Triple::ppc64: -- g_host_arch_64.SetTriple(triple); -- g_supports_64 = true; -- break; -- } -- -- g_supports_32 = g_host_arch_32.IsValid(); -- g_supports_64 = g_host_arch_64.IsValid(); -- } -- --#endif // #else for #if defined (__APPLE__) -- -- if (arch_kind == eSystemDefaultArchitecture32) -- return g_host_arch_32; -- else if (arch_kind == eSystemDefaultArchitecture64) -- return g_host_arch_64; -- -- if (g_supports_64) -- return g_host_arch_64; -- -- return g_host_arch_32; --} -- --const ConstString & --Host::GetVendorString() --{ -- static ConstString g_vendor; -- if (!g_vendor) -- { -- const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture); -- const llvm::StringRef &str_ref = host_arch.GetTriple().getVendorName(); -- g_vendor.SetCStringWithLength(str_ref.data(), str_ref.size()); -- } -- return g_vendor; --} -- --const ConstString & --Host::GetOSString() --{ -- static ConstString g_os_string; -- if (!g_os_string) -- { -- const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture); -- const llvm::StringRef &str_ref = host_arch.GetTriple().getOSName(); -- g_os_string.SetCStringWithLength(str_ref.data(), str_ref.size()); -- } -- return g_os_string; --} -- --const ConstString & --Host::GetTargetTriple() --{ -- static ConstString g_host_triple; -- if (!(g_host_triple)) -- { -- const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture); -- g_host_triple.SetCString(host_arch.GetTriple().getTriple().c_str()); -- } -- return g_host_triple; --} -- --lldb::pid_t --Host::GetCurrentProcessID() --{ -- return ::getpid(); --} -- --lldb::tid_t --Host::GetCurrentThreadID() --{ --#if defined (__APPLE__) -- // Calling "mach_port_deallocate()" bumps the reference count on the thread -- // port, so we need to deallocate it. mach_task_self() doesn't bump the ref -- // count. -- thread_port_t thread_self = mach_thread_self(); -- mach_port_deallocate(mach_task_self(), thread_self); -- return thread_self; --#elif defined(__FreeBSD__) -- return lldb::tid_t(pthread_getthreadid_np()); --#else -- return lldb::tid_t(pthread_self()); --#endif --} -- --lldb::thread_t --Host::GetCurrentThread () --{ -- return lldb::thread_t(pthread_self()); --} -- --const char * --Host::GetSignalAsCString (int signo) --{ -- switch (signo) -- { -- case SIGHUP: return "SIGHUP"; // 1 hangup -- case SIGINT: return "SIGINT"; // 2 interrupt -- case SIGQUIT: return "SIGQUIT"; // 3 quit -- case SIGILL: return "SIGILL"; // 4 illegal instruction (not reset when caught) -- case SIGTRAP: return "SIGTRAP"; // 5 trace trap (not reset when caught) -- case SIGABRT: return "SIGABRT"; // 6 abort() --#if (defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE)) -- case SIGPOLL: return "SIGPOLL"; // 7 pollable event ([XSR] generated, not supported) --#endif --#if !defined(_POSIX_C_SOURCE) -- case SIGEMT: return "SIGEMT"; // 7 EMT instruction --#endif -- case SIGFPE: return "SIGFPE"; // 8 floating point exception -- case SIGKILL: return "SIGKILL"; // 9 kill (cannot be caught or ignored) -- case SIGBUS: return "SIGBUS"; // 10 bus error -- case SIGSEGV: return "SIGSEGV"; // 11 segmentation violation -- case SIGSYS: return "SIGSYS"; // 12 bad argument to system call -- case SIGPIPE: return "SIGPIPE"; // 13 write on a pipe with no one to read it -- case SIGALRM: return "SIGALRM"; // 14 alarm clock -- case SIGTERM: return "SIGTERM"; // 15 software termination signal from kill -- case SIGURG: return "SIGURG"; // 16 urgent condition on IO channel -- case SIGSTOP: return "SIGSTOP"; // 17 sendable stop signal not from tty -- case SIGTSTP: return "SIGTSTP"; // 18 stop signal from tty -- case SIGCONT: return "SIGCONT"; // 19 continue a stopped process -- case SIGCHLD: return "SIGCHLD"; // 20 to parent on child stop or exit -- case SIGTTIN: return "SIGTTIN"; // 21 to readers pgrp upon background tty read -- case SIGTTOU: return "SIGTTOU"; // 22 like TTIN for output if (tp->t_local<OSTOP) --#if !defined(_POSIX_C_SOURCE) -- case SIGIO: return "SIGIO"; // 23 input/output possible signal --#endif -- case SIGXCPU: return "SIGXCPU"; // 24 exceeded CPU time limit -- case SIGXFSZ: return "SIGXFSZ"; // 25 exceeded file size limit -- case SIGVTALRM: return "SIGVTALRM"; // 26 virtual time alarm -- case SIGPROF: return "SIGPROF"; // 27 profiling time alarm --#if !defined(_POSIX_C_SOURCE) -- case SIGWINCH: return "SIGWINCH"; // 28 window size changes -- case SIGINFO: return "SIGINFO"; // 29 information request --#endif -- case SIGUSR1: return "SIGUSR1"; // 30 user defined signal 1 -- case SIGUSR2: return "SIGUSR2"; // 31 user defined signal 2 -- default: -- break; -- } -- return NULL; --} -- --void --Host::WillTerminate () --{ --} -- --#if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__linux__) && !defined(__FreeBSD_kernel__) // see macosx/Host.mm -- -- --void --Host::ThreadCreated (const char *thread_name) --{ --} -- --void --Host::Backtrace (Stream &strm, uint32_t max_frames) --{ -- // TODO: Is there a way to backtrace the current process on linux? Other systems? --} -- --size_t --Host::GetEnvironment (StringList &env) --{ -- // TODO: Is there a way to the host environment for this process on linux? Other systems? -- return 0; --} -- --#endif // #if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__linux__) -- --struct HostThreadCreateInfo --{ -- std::string thread_name; -- thread_func_t thread_fptr; -- thread_arg_t thread_arg; -- -- HostThreadCreateInfo (const char *name, thread_func_t fptr, thread_arg_t arg) : -- thread_name (name ? name : ""), -- thread_fptr (fptr), -- thread_arg (arg) -- { -- } --}; -- --static thread_result_t --ThreadCreateTrampoline (thread_arg_t arg) --{ -- HostThreadCreateInfo *info = (HostThreadCreateInfo *)arg; -- Host::ThreadCreated (info->thread_name.c_str()); -- thread_func_t thread_fptr = info->thread_fptr; -- thread_arg_t thread_arg = info->thread_arg; -- -- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD)); -- if (log) -- log->Printf("thread created"); -- -- delete info; -- return thread_fptr (thread_arg); --} -- --lldb::thread_t --Host::ThreadCreate --( -- const char *thread_name, -- thread_func_t thread_fptr, -- thread_arg_t thread_arg, -- Error *error --) --{ -- lldb::thread_t thread = LLDB_INVALID_HOST_THREAD; -- -- // Host::ThreadCreateTrampoline will delete this pointer for us. -- HostThreadCreateInfo *info_ptr = new HostThreadCreateInfo (thread_name, thread_fptr, thread_arg); -- -- int err = ::pthread_create (&thread, NULL, ThreadCreateTrampoline, info_ptr); -- if (err == 0) -- { -- if (error) -- error->Clear(); -- return thread; -- } -- -- if (error) -- error->SetError (err, eErrorTypePOSIX); -- -- return LLDB_INVALID_HOST_THREAD; --} -- --bool --Host::ThreadCancel (lldb::thread_t thread, Error *error) --{ -- int err = ::pthread_cancel (thread); -- if (error) -- error->SetError(err, eErrorTypePOSIX); -- return err == 0; --} -- --bool --Host::ThreadDetach (lldb::thread_t thread, Error *error) --{ -- int err = ::pthread_detach (thread); -- if (error) -- error->SetError(err, eErrorTypePOSIX); -- return err == 0; --} -- --bool --Host::ThreadJoin (lldb::thread_t thread, thread_result_t *thread_result_ptr, Error *error) --{ -- int err = ::pthread_join (thread, thread_result_ptr); -- if (error) -- error->SetError(err, eErrorTypePOSIX); -- return err == 0; --} -- -- --std::string --Host::GetThreadName (lldb::pid_t pid, lldb::tid_t tid) --{ -- std::string thread_name; --#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 -- // We currently can only get the name of a thread in the current process. -- if (pid == Host::GetCurrentProcessID()) -- { -- char pthread_name[1024]; -- if (::pthread_getname_np (::pthread_from_mach_thread_np (tid), pthread_name, sizeof(pthread_name)) == 0) -- { -- if (pthread_name[0]) -- { -- thread_name = pthread_name; -- } -- } -- else -- { -- dispatch_queue_t current_queue = ::dispatch_get_current_queue (); -- if (current_queue != NULL) -- { -- const char *queue_name = dispatch_queue_get_label (current_queue); -- if (queue_name && queue_name[0]) -- { -- thread_name = queue_name; -- } -- } -- } -- } --#endif -- return thread_name; --} -- --bool --Host::SetThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name) --{ --#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 -- lldb::pid_t curr_pid = Host::GetCurrentProcessID(); -- lldb::tid_t curr_tid = Host::GetCurrentThreadID(); -- if (pid == LLDB_INVALID_PROCESS_ID) -- pid = curr_pid; -- -- if (tid == LLDB_INVALID_THREAD_ID) -- tid = curr_tid; -- -- // Set the pthread name if possible -- if (pid == curr_pid && tid == curr_tid) -- { -- if (::pthread_setname_np (name) == 0) -- return true; -- } -- return false; --#elif defined (__linux__) -- void *fn = dlsym (RTLD_DEFAULT, "pthread_setname_np"); -- if (fn) -- { -- int (*pthread_setname_np_func)(pthread_t thread, const char *name); -- *reinterpret_cast (&pthread_setname_np_func) = fn; -- -- lldb::pid_t curr_pid = Host::GetCurrentProcessID(); -- lldb::tid_t curr_tid = Host::GetCurrentThreadID(); -- -- if (pid == LLDB_INVALID_PROCESS_ID) -- pid = curr_pid; -- -- if (tid == LLDB_INVALID_THREAD_ID) -- tid = curr_tid; -- -- if (pid == curr_pid) -- { -- if (pthread_setname_np_func (tid, name) == 0) -- return true; -- } -- } -- return false; --#else -- return false; --#endif --} -- --FileSpec --Host::GetProgramFileSpec () --{ -- static FileSpec g_program_filespec; -- if (!g_program_filespec) -- { --#if defined (__APPLE__) -- char program_fullpath[PATH_MAX]; -- // If DST is NULL, then return the number of bytes needed. -- uint32_t len = sizeof(program_fullpath); -- int err = _NSGetExecutablePath (program_fullpath, &len); -- if (err == 0) -- g_program_filespec.SetFile (program_fullpath, false); -- else if (err == -1) -- { -- char *large_program_fullpath = (char *)::malloc (len + 1); -- -- err = _NSGetExecutablePath (large_program_fullpath, &len); -- if (err == 0) -- g_program_filespec.SetFile (large_program_fullpath, false); -- -- ::free (large_program_fullpath); -- } --#elif defined (__linux__) -- char exe_path[PATH_MAX]; -- ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1); -- if (len > 0) { -- exe_path[len] = 0; -- g_program_filespec.SetFile(exe_path, false); -- } --#elif defined (__FreeBSD__) -- int exe_path_mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, getpid() }; -- size_t exe_path_size; -- if (sysctl(exe_path_mib, 4, NULL, &exe_path_size, NULL, 0) == 0) -- { -- char *exe_path = new char[exe_path_size]; -- if (sysctl(exe_path_mib, 4, exe_path, &exe_path_size, NULL, 0) == 0) -- g_program_filespec.SetFile(exe_path, false); -- delete[] exe_path; -- } --#endif -- } -- return g_program_filespec; --} -- --FileSpec --Host::GetModuleFileSpecForHostAddress (const void *host_addr) --{ -- FileSpec module_filespec; -- Dl_info info; -- if (::dladdr (host_addr, &info)) -- { -- if (info.dli_fname) -- module_filespec.SetFile(info.dli_fname, true); -- } -- return module_filespec; --} -- --#if !defined (__APPLE__) // see Host.mm -- --bool --Host::GetBundleDirectory (const FileSpec &file, FileSpec &bundle) --{ -- bundle.Clear(); -- return false; --} -- --bool --Host::ResolveExecutableInBundle (FileSpec &file) --{ -- return false; --} --#endif -- --// Opaque info that tracks a dynamic library that was loaded --struct DynamicLibraryInfo --{ -- DynamicLibraryInfo (const FileSpec &fs, int o, void *h) : -- file_spec (fs), -- open_options (o), -- handle (h) -- { -- } -- -- const FileSpec file_spec; -- uint32_t open_options; -- void * handle; --}; -- --void * --Host::DynamicLibraryOpen (const FileSpec &file_spec, uint32_t options, Error &error) --{ -- char path[PATH_MAX]; -- if (file_spec.GetPath(path, sizeof(path))) -- { -- int mode = 0; -- -- if (options & eDynamicLibraryOpenOptionLazy) -- mode |= RTLD_LAZY; -- else -- mode |= RTLD_NOW; -- -- -- if (options & eDynamicLibraryOpenOptionLocal) -- mode |= RTLD_LOCAL; -- else -- mode |= RTLD_GLOBAL; -- --#ifdef LLDB_CONFIG_DLOPEN_RTLD_FIRST_SUPPORTED -- if (options & eDynamicLibraryOpenOptionLimitGetSymbol) -- mode |= RTLD_FIRST; --#endif -- -- void * opaque = ::dlopen (path, mode); -- -- if (opaque) -- { -- error.Clear(); -- return new DynamicLibraryInfo (file_spec, options, opaque); -- } -- else -- { -- error.SetErrorString(::dlerror()); -- } -- } -- else -- { -- error.SetErrorString("failed to extract path"); -- } -- return NULL; --} -- --Error --Host::DynamicLibraryClose (void *opaque) --{ -- Error error; -- if (opaque == NULL) -- { -- error.SetErrorString ("invalid dynamic library handle"); -- } -- else -- { -- DynamicLibraryInfo *dylib_info = (DynamicLibraryInfo *) opaque; -- if (::dlclose (dylib_info->handle) != 0) -- { -- error.SetErrorString(::dlerror()); -- } -- -- dylib_info->open_options = 0; -- dylib_info->handle = 0; -- delete dylib_info; -- } -- return error; --} -- --void * --Host::DynamicLibraryGetSymbol (void *opaque, const char *symbol_name, Error &error) --{ -- if (opaque == NULL) -- { -- error.SetErrorString ("invalid dynamic library handle"); -- } -- else -- { -- DynamicLibraryInfo *dylib_info = (DynamicLibraryInfo *) opaque; -- -- void *symbol_addr = ::dlsym (dylib_info->handle, symbol_name); -- if (symbol_addr) -- { --#ifndef LLDB_CONFIG_DLOPEN_RTLD_FIRST_SUPPORTED -- // This host doesn't support limiting searches to this shared library -- // so we need to verify that the match came from this shared library -- // if it was requested in the Host::DynamicLibraryOpen() function. -- if (dylib_info->open_options & eDynamicLibraryOpenOptionLimitGetSymbol) -- { -- FileSpec match_dylib_spec (Host::GetModuleFileSpecForHostAddress (symbol_addr)); -- if (match_dylib_spec != dylib_info->file_spec) -- { -- char dylib_path[PATH_MAX]; -- if (dylib_info->file_spec.GetPath (dylib_path, sizeof(dylib_path))) -- error.SetErrorStringWithFormat ("symbol not found in \"%s\"", dylib_path); -- else -- error.SetErrorString ("symbol not found"); -- return NULL; -- } -- } --#endif -- error.Clear(); -- return symbol_addr; -- } -- else -- { -- error.SetErrorString(::dlerror()); -- } -- } -- return NULL; --} -- --bool --Host::GetLLDBPath (PathType path_type, FileSpec &file_spec) --{ -- // To get paths related to LLDB we get the path to the executable that -- // contains this function. On MacOSX this will be "LLDB.framework/.../LLDB", -- // on linux this is assumed to be the "lldb" main executable. If LLDB on -- // linux is actually in a shared library (lldb.so??) then this function will -- // need to be modified to "do the right thing". -- -- switch (path_type) -- { -- case ePathTypeLLDBShlibDir: -- { -- static ConstString g_lldb_so_dir; -- if (!g_lldb_so_dir) -- { -- FileSpec lldb_file_spec (Host::GetModuleFileSpecForHostAddress ((void *)Host::GetLLDBPath)); -- g_lldb_so_dir = lldb_file_spec.GetDirectory(); -- } -- file_spec.GetDirectory() = g_lldb_so_dir; -- return file_spec.GetDirectory(); -- } -- break; -- -- case ePathTypeSupportExecutableDir: -- { -- static ConstString g_lldb_support_exe_dir; -- if (!g_lldb_support_exe_dir) -- { -- FileSpec lldb_file_spec; -- if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec)) -- { -- char raw_path[PATH_MAX]; -- char resolved_path[PATH_MAX]; -- lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); -- --#if defined (__APPLE__) -- char *framework_pos = ::strstr (raw_path, "LLDB.framework"); -- if (framework_pos) -- { -- framework_pos += strlen("LLDB.framework"); --#if !defined (__arm__) -- ::strncpy (framework_pos, "/Resources", PATH_MAX - (framework_pos - raw_path)); --#endif -- } --#endif -- FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path)); -- g_lldb_support_exe_dir.SetCString(resolved_path); -- } -- } -- file_spec.GetDirectory() = g_lldb_support_exe_dir; -- return file_spec.GetDirectory(); -- } -- break; -- -- case ePathTypeHeaderDir: -- { -- static ConstString g_lldb_headers_dir; -- if (!g_lldb_headers_dir) -- { --#if defined (__APPLE__) -- FileSpec lldb_file_spec; -- if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec)) -- { -- char raw_path[PATH_MAX]; -- char resolved_path[PATH_MAX]; -- lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); -- -- char *framework_pos = ::strstr (raw_path, "LLDB.framework"); -- if (framework_pos) -- { -- framework_pos += strlen("LLDB.framework"); -- ::strncpy (framework_pos, "/Headers", PATH_MAX - (framework_pos - raw_path)); -- } -- FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path)); -- g_lldb_headers_dir.SetCString(resolved_path); -- } --#else -- // TODO: Anyone know how we can determine this for linux? Other systems?? -- g_lldb_headers_dir.SetCString ("/opt/local/include/lldb"); --#endif -- } -- file_spec.GetDirectory() = g_lldb_headers_dir; -- return file_spec.GetDirectory(); -- } -- break; -- -- case ePathTypePythonDir: -- { -- static ConstString g_lldb_python_dir; -- if (!g_lldb_python_dir) -- { -- FileSpec lldb_file_spec; -- if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec)) -- { -- char raw_path[PATH_MAX]; -- char resolved_path[PATH_MAX]; -- lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); -- --#if defined (__APPLE__) -- char *framework_pos = ::strstr (raw_path, "LLDB.framework"); -- if (framework_pos) -- { -- framework_pos += strlen("LLDB.framework"); -- ::strncpy (framework_pos, "/Resources/Python", PATH_MAX - (framework_pos - raw_path)); -- } --#else -- llvm::Twine python_version_dir; -- python_version_dir = "/python" -- + llvm::Twine(PY_MAJOR_VERSION) -- + "." -- + llvm::Twine(PY_MINOR_VERSION) -- + "/site-packages"; -- -- // We may get our string truncated. Should we protect -- // this with an assert? -- -- ::strncat(raw_path, python_version_dir.str().c_str(), -- sizeof(raw_path) - strlen(raw_path) - 1); -- --#endif -- FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path)); -- g_lldb_python_dir.SetCString(resolved_path); -- } -- } -- file_spec.GetDirectory() = g_lldb_python_dir; -- return file_spec.GetDirectory(); -- } -- break; -- -- case ePathTypeLLDBSystemPlugins: // System plug-ins directory -- { --#if defined (__APPLE__) -- static ConstString g_lldb_system_plugin_dir; -- static bool g_lldb_system_plugin_dir_located = false; -- if (!g_lldb_system_plugin_dir_located) -- { -- g_lldb_system_plugin_dir_located = true; -- FileSpec lldb_file_spec; -- if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec)) -- { -- char raw_path[PATH_MAX]; -- char resolved_path[PATH_MAX]; -- lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); -- -- char *framework_pos = ::strstr (raw_path, "LLDB.framework"); -- if (framework_pos) -- { -- framework_pos += strlen("LLDB.framework"); -- ::strncpy (framework_pos, "/Resources/PlugIns", PATH_MAX - (framework_pos - raw_path)); -- FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path)); -- g_lldb_system_plugin_dir.SetCString(resolved_path); -- } -- return false; -- } -- } -- -- if (g_lldb_system_plugin_dir) -- { -- file_spec.GetDirectory() = g_lldb_system_plugin_dir; -- return true; -- } --#endif -- // TODO: where would system LLDB plug-ins be located on linux? Other systems? -- return false; -- } -- break; -- -- case ePathTypeLLDBUserPlugins: // User plug-ins directory -- { --#if defined (__APPLE__) -- static ConstString g_lldb_user_plugin_dir; -- if (!g_lldb_user_plugin_dir) -- { -- char user_plugin_path[PATH_MAX]; -- if (FileSpec::Resolve ("~/Library/Application Support/LLDB/PlugIns", -- user_plugin_path, -- sizeof(user_plugin_path))) -- { -- g_lldb_user_plugin_dir.SetCString(user_plugin_path); -- } -- } -- file_spec.GetDirectory() = g_lldb_user_plugin_dir; -- return file_spec.GetDirectory(); --#endif -- // TODO: where would user LLDB plug-ins be located on linux? Other systems? -- return false; -- } -- } -- -- return false; --} -- -- --bool --Host::GetHostname (std::string &s) --{ -- char hostname[PATH_MAX]; -- hostname[sizeof(hostname) - 1] = '\0'; -- if (::gethostname (hostname, sizeof(hostname) - 1) == 0) -- { -- struct hostent* h = ::gethostbyname (hostname); -- if (h) -- s.assign (h->h_name); -- else -- s.assign (hostname); -- return true; -- } -- return false; --} -- --const char * --Host::GetUserName (uint32_t uid, std::string &user_name) --{ -- struct passwd user_info; -- struct passwd *user_info_ptr = &user_info; -- char user_buffer[PATH_MAX]; -- size_t user_buffer_size = sizeof(user_buffer); -- if (::getpwuid_r (uid, -- &user_info, -- user_buffer, -- user_buffer_size, -- &user_info_ptr) == 0) -- { -- if (user_info_ptr) -- { -- user_name.assign (user_info_ptr->pw_name); -- return user_name.c_str(); -- } -- } -- user_name.clear(); -- return NULL; --} -- --const char * --Host::GetGroupName (uint32_t gid, std::string &group_name) --{ -- char group_buffer[PATH_MAX]; -- size_t group_buffer_size = sizeof(group_buffer); -- struct group group_info; -- struct group *group_info_ptr = &group_info; -- // Try the threadsafe version first -- if (::getgrgid_r (gid, -- &group_info, -- group_buffer, -- group_buffer_size, -- &group_info_ptr) == 0) -- { -- if (group_info_ptr) -- { -- group_name.assign (group_info_ptr->gr_name); -- return group_name.c_str(); -- } -- } -- else -- { -- // The threadsafe version isn't currently working -- // for me on darwin, but the non-threadsafe version -- // is, so I am calling it below. -- group_info_ptr = ::getgrgid (gid); -- if (group_info_ptr) -- { -- group_name.assign (group_info_ptr->gr_name); -- return group_name.c_str(); -- } -- } -- group_name.clear(); -- return NULL; --} -- --#if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined(__FreeBSD_kernel__) // see macosx/Host.mm --bool --Host::GetOSBuildString (std::string &s) --{ -- s.clear(); -- return false; --} -- --bool --Host::GetOSKernelDescription (std::string &s) --{ -- s.clear(); -- return false; --} --#endif -- --uint32_t --Host::GetUserID () --{ -- return getuid(); --} -- --uint32_t --Host::GetGroupID () --{ -- return getgid(); --} -- --uint32_t --Host::GetEffectiveUserID () --{ -- return geteuid(); --} -- --uint32_t --Host::GetEffectiveGroupID () --{ -- return getegid(); --} -- --#if !defined (__APPLE__) && !defined(__linux__) --uint32_t --Host::FindProcesses (const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos) --{ -- process_infos.Clear(); -- return process_infos.GetSize(); --} --#endif // #if !defined (__APPLE__) && !defined(__linux__) -- --#if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined(__linux__)&& !defined(__FreeBSD_kernel__) --bool --Host::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info) --{ -- process_info.Clear(); -- return false; --} --#endif -- --#if !defined(__linux__) --bool --Host::FindProcessThreads (const lldb::pid_t pid, TidMap &tids_to_attach) --{ -- return false; --} --#endif -- --lldb::TargetSP --Host::GetDummyTarget (lldb_private::Debugger &debugger) --{ -- static TargetSP g_dummy_target_sp; -- -- // FIXME: Maybe the dummy target should be per-Debugger -- if (!g_dummy_target_sp || !g_dummy_target_sp->IsValid()) -- { -- ArchSpec arch(Target::GetDefaultArchitecture()); -- if (!arch.IsValid()) -- arch = Host::GetArchitecture (); -- Error err = debugger.GetTargetList().CreateTarget(debugger, -- NULL, -- arch.GetTriple().getTriple().c_str(), -- false, -- NULL, -- g_dummy_target_sp); -- } -- -- return g_dummy_target_sp; --} -- --struct ShellInfo --{ -- ShellInfo () : -- process_reaped (false), -- can_delete (false), -- pid (LLDB_INVALID_PROCESS_ID), -- signo(-1), -- status(-1) -- { -- } -- -- lldb_private::Predicate process_reaped; -- lldb_private::Predicate can_delete; -- lldb::pid_t pid; -- int signo; -- int status; --}; -- --static bool --MonitorShellCommand (void *callback_baton, -- lldb::pid_t pid, -- bool exited, // True if the process did exit -- int signo, // Zero for no signal -- int status) // Exit value of process if signal is zero --{ -- ShellInfo *shell_info = (ShellInfo *)callback_baton; -- shell_info->pid = pid; -- shell_info->signo = signo; -- shell_info->status = status; -- // Let the thread running Host::RunShellCommand() know that the process -- // exited and that ShellInfo has been filled in by broadcasting to it -- shell_info->process_reaped.SetValue(1, eBroadcastAlways); -- // Now wait for a handshake back from that thread running Host::RunShellCommand -- // so we know that we can delete shell_info_ptr -- shell_info->can_delete.WaitForValueEqualTo(true); -- // Sleep a bit to allow the shell_info->can_delete.SetValue() to complete... -- usleep(1000); -- // Now delete the shell info that was passed into this function -- delete shell_info; -- return true; --} -- --Error --Host::RunShellCommand (const char *command, -- const char *working_dir, -- int *status_ptr, -- int *signo_ptr, -- std::string *command_output_ptr, -- uint32_t timeout_sec, -- const char *shell) --{ -- Error error; -- ProcessLaunchInfo launch_info; -- if (shell && shell[0]) -- { -- // Run the command in a shell -- launch_info.SetShell(shell); -- launch_info.GetArguments().AppendArgument(command); -- const bool localhost = true; -- const bool will_debug = false; -- const bool first_arg_is_full_shell_command = true; -- launch_info.ConvertArgumentsForLaunchingInShell (error, -- localhost, -- will_debug, -- first_arg_is_full_shell_command); -- } -- else -- { -- // No shell, just run it -- Args args (command); -- const bool first_arg_is_executable = true; -- launch_info.SetArguments(args, first_arg_is_executable); -- } -- -- if (working_dir) -- launch_info.SetWorkingDirectory(working_dir); -- char output_file_path_buffer[L_tmpnam]; -- const char *output_file_path = NULL; -- if (command_output_ptr) -- { -- // Create a temporary file to get the stdout/stderr and redirect the -- // output of the command into this file. We will later read this file -- // if all goes well and fill the data into "command_output_ptr" -- output_file_path = ::tmpnam(output_file_path_buffer); -- launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false); -- launch_info.AppendOpenFileAction(STDOUT_FILENO, output_file_path, false, true); -- launch_info.AppendDuplicateFileAction(STDOUT_FILENO, STDERR_FILENO); -- } -- else -- { -- launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false); -- launch_info.AppendSuppressFileAction (STDOUT_FILENO, false, true); -- launch_info.AppendSuppressFileAction (STDERR_FILENO, false, true); -- } -- -- // The process monitor callback will delete the 'shell_info_ptr' below... -- std::unique_ptr shell_info_ap (new ShellInfo()); -- -- const bool monitor_signals = false; -- launch_info.SetMonitorProcessCallback(MonitorShellCommand, shell_info_ap.get(), monitor_signals); -- -- error = LaunchProcess (launch_info); -- const lldb::pid_t pid = launch_info.GetProcessID(); -- if (pid != LLDB_INVALID_PROCESS_ID) -- { -- // The process successfully launched, so we can defer ownership of -- // "shell_info" to the MonitorShellCommand callback function that will -- // get called when the process dies. We release the unique pointer as it -- // doesn't need to delete the ShellInfo anymore. -- ShellInfo *shell_info = shell_info_ap.release(); -- TimeValue timeout_time(TimeValue::Now()); -- timeout_time.OffsetWithSeconds(timeout_sec); -- bool timed_out = false; -- shell_info->process_reaped.WaitForValueEqualTo(true, &timeout_time, &timed_out); -- if (timed_out) -- { -- error.SetErrorString("timed out waiting for shell command to complete"); -- -- // Kill the process since it didn't complete withint the timeout specified -- ::kill (pid, SIGKILL); -- // Wait for the monitor callback to get the message -- timeout_time = TimeValue::Now(); -- timeout_time.OffsetWithSeconds(1); -- timed_out = false; -- shell_info->process_reaped.WaitForValueEqualTo(true, &timeout_time, &timed_out); -- } -- else -- { -- if (status_ptr) -- *status_ptr = shell_info->status; -- -- if (signo_ptr) -- *signo_ptr = shell_info->signo; -- -- if (command_output_ptr) -- { -- command_output_ptr->clear(); -- FileSpec file_spec(output_file_path, File::eOpenOptionRead); -- uint64_t file_size = file_spec.GetByteSize(); -- if (file_size > 0) -- { -- if (file_size > command_output_ptr->max_size()) -- { -- error.SetErrorStringWithFormat("shell command output is too large to fit into a std::string"); -- } -- else -- { -- command_output_ptr->resize(file_size); -- file_spec.ReadFileContents(0, &((*command_output_ptr)[0]), command_output_ptr->size(), &error); -- } -- } -- } -- } -- shell_info->can_delete.SetValue(true, eBroadcastAlways); -- } -- else -- { -- error.SetErrorString("failed to get process ID"); -- } -- -- if (output_file_path) -- ::unlink (output_file_path); -- // Handshake with the monitor thread, or just let it know in advance that -- // it can delete "shell_info" in case we timed out and were not able to kill -- // the process... -- return error; --} -- -- --uint32_t --Host::GetNumberCPUS () --{ -- static uint32_t g_num_cores = UINT32_MAX; -- if (g_num_cores == UINT32_MAX) -- { --#if defined(__APPLE__) or defined (__linux__) or defined (__FreeBSD__) -- -- g_num_cores = ::sysconf(_SC_NPROCESSORS_ONLN); -- --#elif defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -- -- // Header file for this might need to be included at the top of this file -- SYSTEM_INFO system_info; -- ::GetSystemInfo (&system_info); -- g_num_cores = system_info.dwNumberOfProcessors; -- --#else -- -- // Assume POSIX support if a host specific case has not been supplied above -- g_num_cores = 0; -- int num_cores = 0; -- size_t num_cores_len = sizeof(num_cores); --#ifdef HW_AVAILCPU -- int mib[] = { CTL_HW, HW_AVAILCPU }; --#else -- int mib[] = { CTL_HW, HW_NCPU }; --#endif -- -- /* get the number of CPUs from the system */ -- if (sysctl(mib, sizeof(mib)/sizeof(int), &num_cores, &num_cores_len, NULL, 0) == 0 && (num_cores > 0)) -- { -- g_num_cores = num_cores; -- } -- else -- { -- mib[1] = HW_NCPU; -- num_cores_len = sizeof(num_cores); -- if (sysctl(mib, sizeof(mib)/sizeof(int), &num_cores, &num_cores_len, NULL, 0) == 0 && (num_cores > 0)) -- { -- if (num_cores > 0) -- g_num_cores = num_cores; -- } -- } --#endif -- } -- return g_num_cores; --} -- -- -- --#if !defined (__APPLE__) --bool --Host::OpenFileInExternalEditor (const FileSpec &file_spec, uint32_t line_no) --{ -- return false; --} -- --void --Host::SetCrashDescriptionWithFormat (const char *format, ...) --{ --} -- --void --Host::SetCrashDescription (const char *description) --{ --} -- --lldb::pid_t --LaunchApplication (const FileSpec &app_file_spec) --{ -- return LLDB_INVALID_PROCESS_ID; --} -- --#endif Index: llvm-toolchain-3.3-3.3/lldb/source/Host/common/Host.cpp =================================================================== --- llvm-toolchain-3.3-3.3.orig/lldb/source/Host/common/Host.cpp 2013-08-28 10:29:30.000000000 +0000 From 6d02a91140be8a440206f9baef8550893a971bbf Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 5 Sep 2013 05:55:16 +0000 Subject: [PATCH 14/14] clang under KfFreeBSD was not exporting the correct defines (Closes: #721880) --- debian/changelog | 4 ++ .../patches/kfreebsd_target_info_clang33.diff | 51 +++++++++++++++++++ debian/patches/series | 1 + 3 files changed, 56 insertions(+) create mode 100644 debian/patches/kfreebsd_target_info_clang33.diff diff --git a/debian/changelog b/debian/changelog index 7ab9d71a..e5120bfe 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,10 @@ llvm-toolchain-3.3 (1:3.3-9) unstable; urgency=low See libstdc++-header-i386.diff. (Closes: #714890) * Add more fixes for the HURD port... (but still fails) + [ Robert Millan ] + * clang under KfFreeBSD was not exporting the correct defines + (Closes: #721880) + [ Jon Severinsson ] * Merge from llvm-toolchain-3.2 branch up to 3.2repack-11. * Drop auto-generated file debian/libllvm3.3.install. diff --git a/debian/patches/kfreebsd_target_info_clang33.diff b/debian/patches/kfreebsd_target_info_clang33.diff new file mode 100644 index 00000000..2453068b --- /dev/null +++ b/debian/patches/kfreebsd_target_info_clang33.diff @@ -0,0 +1,51 @@ +--- a/clang/lib/Basic/Targets.cpp ++++ b/clang/lib/Basic/Targets.cpp +@@ -283,6 +283,30 @@ + } + }; + ++// GNU/kFreeBSD Target ++template ++class KFreeBSDTargetInfo : public OSTargetInfo { ++protected: ++ virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, ++ MacroBuilder &Builder) const { ++ // GNU/kFreeBSD defines; list based off of gcc output ++ ++ DefineStd(Builder, "unix", Opts); ++ Builder.defineMacro("__FreeBSD_kernel__"); ++ Builder.defineMacro("__GLIBC__"); ++ Builder.defineMacro("__ELF__"); ++ if (Opts.POSIXThreads) ++ Builder.defineMacro("_REENTRANT"); ++ if (Opts.CPlusPlus) ++ Builder.defineMacro("_GNU_SOURCE"); ++ } ++public: ++ KFreeBSDTargetInfo(const std::string &triple) ++ : OSTargetInfo(triple) { ++ this->UserLabelPrefix = ""; ++ } ++}; ++ + // Minix Target + template + class MinixTargetInfo : public OSTargetInfo { +@@ -5434,6 +5458,8 @@ + return new BitrigI386TargetInfo(T); + case llvm::Triple::FreeBSD: + return new FreeBSDTargetInfo(T); ++ case llvm::Triple::KFreeBSD: ++ return new KFreeBSDTargetInfo(T); + case llvm::Triple::Minix: + return new MinixTargetInfo(T); + case llvm::Triple::Solaris: +@@ -5473,6 +5499,8 @@ + return new BitrigX86_64TargetInfo(T); + case llvm::Triple::FreeBSD: + return new FreeBSDTargetInfo(T); ++ case llvm::Triple::KFreeBSD: ++ return new KFreeBSDTargetInfo(T); + case llvm::Triple::Solaris: + return new SolarisTargetInfo(T); + case llvm::Triple::MinGW32: diff --git a/debian/patches/series b/debian/patches/series index eb0f56b6..1d2eb3d5 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -34,3 +34,4 @@ hurd-pathmax.diff libprofile_rt_sparc.patch lldb-hurd.diff libstdc++-header-i386.diff +kfreebsd_target_info_clang33.diff