mirror of
https://github.com/Relintai/osxcross.git
synced 2025-02-03 22:45:56 +01:00
Add llvm-dsymutil build script + re-add 7e9f85
This finally makes proper debugging possible
This commit is contained in:
parent
4debfb6b45
commit
08414886fb
@ -14,6 +14,8 @@ added:
|
||||
o32-clang++-stdc++ --> uses the SDK's libstdc++
|
||||
o32-clang++-gstdc++ --> uses gcc's (build_gcc.sh) libstdc++
|
||||
* unit tests (wrapper)
|
||||
* llvm-dsymutil build script
|
||||
* dsymutil is now wrapped to llvm-dsymutil (LLVM >= 3.8 only)
|
||||
|
||||
/****************************** v0.10 ********************************/
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
## COMPILER-RT ##
|
||||
|
||||
### WHAT IS COMPILER-RT: ###
|
||||
### WHAT IS COMPILER-RT? ###
|
||||
|
||||
Please see http://compiler-rt.llvm.org/.
|
||||
Please see http://compiler-rt.llvm.org.
|
||||
|
||||
### INSTALLATION: ###
|
||||
|
||||
@ -24,6 +24,8 @@ You do not need to do anything, clang's doing the job for you.
|
||||
However, `-fsanitize=address` is a bit annoying because the address sanitizer library is linked
|
||||
dynamically, and thus requires you to copy the ASAN runtime library onto the target system.
|
||||
|
||||
\[See [README.DEBUGGING](README.DEBUGGING.md) in how to get a backtrace with line numbers and symbol names]
|
||||
|
||||
The following example illustrates how to achieve this:
|
||||
|
||||
# Example source code.
|
||||
|
22
README.DEBUGGING.md
Normal file
22
README.DEBUGGING.md
Normal file
@ -0,0 +1,22 @@
|
||||
### Requirements: ###
|
||||
|
||||
* llvm-dsymutil (>= 3.8)
|
||||
* A Mac OS X system with lldb / gdb installed
|
||||
|
||||
### Setting up llvm-dsymutil: ###
|
||||
|
||||
First of all, you **really** need llvm-dsymutil from llvm 3.8 (trunk as of writing),
|
||||
llvm 3.7 or earlier **is not** sufficient.
|
||||
|
||||
Run `./build_llvm_dsymutil.sh` to build and install llvm-dsymutil to target/bin.
|
||||
|
||||
`dsymutil` is a no-op if you do not have [osxcross-]llvm-dsymutil >= 3.8 in PATH.
|
||||
|
||||
### Debug Example: ###
|
||||
|
||||
* Build your application with `-g`
|
||||
* [LTO only] Add `-Wl,-object_path_lto,lto.o` to the linker flags
|
||||
* After linking run: `dsymutil binary`
|
||||
* [Optional] Strip the binary: `x86_64-apple-darwinXX-strip binary`
|
||||
* Copy the binary **and** the created `<binary>.dSYM` "folder" onto the target Mac OS X system
|
||||
* Debug the binary as usual
|
37
build_llvm_dsymutil.sh
Executable file
37
build_llvm_dsymutil.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
pushd "${0%/*}" &>/dev/null
|
||||
|
||||
DESC="llvm-dsymutil"
|
||||
source tools/tools.sh
|
||||
eval $(tools/osxcross_conf.sh)
|
||||
|
||||
require git
|
||||
require cmake
|
||||
|
||||
pushd $OSXCROSS_BUILD_DIR &>/dev/null
|
||||
|
||||
if [ ! -e llvm-dsymutil/.clone_complete ]; then
|
||||
rm -rf llvm-dsymutil
|
||||
# Vanilla llvm-dsymutil with a few patches on top for OSXCross
|
||||
git clone https://github.com/tpoechtrager/llvm-dsymutil.git --depth 1
|
||||
fi
|
||||
|
||||
pushd llvm-dsymutil &>/dev/null
|
||||
|
||||
git clean -fdx
|
||||
touch .clone_complete
|
||||
git pull
|
||||
|
||||
mkdir build
|
||||
pushd build &>/dev/null
|
||||
|
||||
cmake .. \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64" \
|
||||
-DLLVM_ENABLE_ASSERTIONS=Off
|
||||
|
||||
$MAKE -f tools/dsymutil/Makefile -j$JOBS
|
||||
cp bin/llvm-dsymutil $OSXCROSS_TARGET_DIR/bin/osxcross-llvm-dsymutil
|
||||
|
||||
echo "installed llvm-dsymutil to $OSXCROSS_TARGET_DIR/bin/osxcross-llvm-dsymutil"
|
4
tools/tools.sh
Executable file → Normal file
4
tools/tools.sh
Executable file → Normal file
@ -67,13 +67,15 @@ if [[ $SCRIPT != *wrapper/build.sh ]]; then
|
||||
$SCRIPT != "mount_xcode_image.sh" -a \
|
||||
$SCRIPT != "gen_sdk_package_darling_dmg.sh" -a \
|
||||
$SCRIPT != "gen_sdk_package_p7zip.sh" ]; then
|
||||
eval $(tools/osxcross_conf.sh)
|
||||
res=$(tools/osxcross_conf.sh)
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -n "you need to complete ./build.sh first, before you can start "
|
||||
echo "building $DESC"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
eval "$res"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
@ -57,7 +57,8 @@ SRCS= \
|
||||
programs/osxcross-man.cpp \
|
||||
programs/sw_vers.cpp \
|
||||
programs/pkg-config.cpp \
|
||||
programs/xcrun.cpp
|
||||
programs/xcrun.cpp \
|
||||
programs/dsymutil.cpp
|
||||
|
||||
OBJS=$(subst .cpp,.o,$(SRCS))
|
||||
|
||||
|
@ -47,9 +47,10 @@
|
||||
using namespace tools;
|
||||
using namespace target;
|
||||
|
||||
namespace {
|
||||
|
||||
int unittest = 0;
|
||||
int debug = 0;
|
||||
|
||||
namespace {
|
||||
|
||||
void warnExtension(const char *extension) {
|
||||
static bool noextwarnings = !!getenv("OSXCROSS_NO_EXTENSION_WARNINGS");
|
||||
@ -441,7 +442,6 @@ int main(int argc, char **argv) {
|
||||
auto b = new (bbuf) benchmark;
|
||||
Target target;
|
||||
char **cargs = nullptr;
|
||||
int debug = 0;
|
||||
int rc = -1;
|
||||
|
||||
if (char *p = getenv("OCDEBUG"))
|
||||
|
108
wrapper/programs/dsymutil.cpp
Normal file
108
wrapper/programs/dsymutil.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
/***********************************************************************
|
||||
* OSXCross Compiler Wrapper *
|
||||
* Copyright (C) 2014, 2015 by Thomas Poechtrager *
|
||||
* t.poechtrager@gmail.com *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software *
|
||||
* Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
***********************************************************************/
|
||||
|
||||
#include "proginc.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
using namespace tools;
|
||||
|
||||
namespace program {
|
||||
|
||||
int dsymutil(int argc, char **argv, Target &target) {
|
||||
(void)argc;
|
||||
|
||||
std::string dsymutil;
|
||||
char LLVMDsymutilVersionOutput[1024];
|
||||
const char *LLVMDsymutilVersionStr;
|
||||
LLVMVersion LLVMDsymutilVersion;
|
||||
|
||||
const std::string &ParentProcessName = getParentProcessName();
|
||||
|
||||
if (!debug && ParentProcessName.find("clang") == std::string::npos &&
|
||||
ParentProcessName != "collect2" && ParentProcessName != "unknown")
|
||||
debug = 1;
|
||||
|
||||
if (char *p = getenv("OSXCROSS_LLVM_DSYMUTIL")) {
|
||||
dsymutil = p;
|
||||
debug = 1;
|
||||
} else {
|
||||
if (!realPath("osxcross-llvm-dsymutil", dsymutil) &&
|
||||
!realPath("llvm-dsymutil", dsymutil)) {
|
||||
if (debug)
|
||||
dbg << "dsymutil: cannot find [osxcross-]llvm-dsymutil in PATH"
|
||||
<< dbg.endl();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::string command = dsymutil + " -version";
|
||||
|
||||
if (runcommand(command.c_str(), LLVMDsymutilVersionOutput,
|
||||
sizeof(LLVMDsymutilVersionOutput)) == RUNCOMMAND_ERROR) {
|
||||
if (debug)
|
||||
dbg << "dsymutil: executing \"" << command << "\" failed"
|
||||
<< dbg.endl();
|
||||
return 0;
|
||||
}
|
||||
|
||||
LLVMDsymutilVersionStr = strstr(LLVMDsymutilVersionOutput, "LLVM version ");
|
||||
|
||||
if (!LLVMDsymutilVersionStr) {
|
||||
if (debug)
|
||||
dbg << "dsymutil: unable to parse llvm-dsymutil version"
|
||||
<< dbg.endl();
|
||||
return 0;
|
||||
}
|
||||
|
||||
LLVMDsymutilVersionStr += 13; // strlen("LLVM version ");
|
||||
|
||||
LLVMDsymutilVersion = parseLLVMVersion(LLVMDsymutilVersionStr);
|
||||
|
||||
constexpr LLVMVersion RequiredLLVMDsymutilVersion(3, 8);
|
||||
|
||||
if (LLVMDsymutilVersion < RequiredLLVMDsymutilVersion) {
|
||||
if (debug)
|
||||
dbg << "ignoring dsymutil invocation: '"
|
||||
<< dsymutil << "' is too old ("
|
||||
<< LLVMDsymutilVersion.Str() << " < "
|
||||
<< RequiredLLVMDsymutilVersion.Str() << ")"
|
||||
<< dbg.endl();
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::stringstream lipo;
|
||||
std::string triple;
|
||||
|
||||
lipo << target.execpath << PATHDIV
|
||||
<< target.getDefaultTriple(triple) << "-lipo";
|
||||
|
||||
setenv("LIPO", lipo.str().c_str(), 1);
|
||||
|
||||
if (execvp(dsymutil.c_str(), argv))
|
||||
err << "cannot execute '" << dsymutil << "'" << err.endl();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
} // namespace program
|
@ -11,3 +11,6 @@
|
||||
#include "tools.h"
|
||||
#include "target.h"
|
||||
#include "progs.h"
|
||||
|
||||
extern int debug;
|
||||
extern int unittest;
|
||||
|
@ -78,6 +78,7 @@ private:
|
||||
|
||||
int sw_vers(int argc, char **argv, target::Target &target);
|
||||
int xcrun(int argc, char **argv, Target &target);
|
||||
int dsymutil(int argc, char **argv, target::Target &target);
|
||||
|
||||
namespace osxcross {
|
||||
int version();
|
||||
@ -93,7 +94,7 @@ static int dummy() { return 0; }
|
||||
constexpr prog programs[] = {
|
||||
{ "sw_vers", sw_vers },
|
||||
{ "xcrun", xcrun },
|
||||
{ "dsymutil", dummy },
|
||||
{ "dsymutil", dsymutil },
|
||||
{ "osxcross", osxcross::version },
|
||||
{ "osxcross-env", osxcross::env },
|
||||
{ "osxcross-conf", osxcross::conf },
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <climits>
|
||||
#include <cassert>
|
||||
@ -538,6 +539,36 @@ const char *getFileExtension(const char *file) {
|
||||
return p;
|
||||
}
|
||||
|
||||
//
|
||||
// Shell Commands
|
||||
//
|
||||
|
||||
size_t runcommand(const char *command, char *buf, size_t len) {
|
||||
#define RETURN(v) \
|
||||
do { \
|
||||
if (p) \
|
||||
pclose(p); \
|
||||
return (v); \
|
||||
} while (0)
|
||||
|
||||
if (!len)
|
||||
return RUNCOMMAND_ERROR;
|
||||
|
||||
FILE *p;
|
||||
size_t outputlen;
|
||||
|
||||
if (!(p = popen(command, "r")))
|
||||
RETURN(RUNCOMMAND_ERROR);
|
||||
|
||||
if (!(outputlen = fread(buf, sizeof(char), len - 1, p)))
|
||||
RETURN(RUNCOMMAND_ERROR);
|
||||
|
||||
buf[outputlen] = '\0';
|
||||
|
||||
RETURN(outputlen);
|
||||
#undef RETURN
|
||||
}
|
||||
|
||||
//
|
||||
// Time
|
||||
//
|
||||
|
@ -213,6 +213,14 @@ template <typename T, size_t size = 0> struct ArgParser {
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Shell Commands
|
||||
//
|
||||
|
||||
constexpr size_t RUNCOMMAND_ERROR = -1;
|
||||
|
||||
size_t runcommand(const char *command, char *buf, size_t len);
|
||||
|
||||
//
|
||||
// Time
|
||||
//
|
||||
@ -325,10 +333,13 @@ static_assert(OSVersion(10, 6) != OSVersion(10, 5), "");
|
||||
OSVersion parseOSVersion(const char *OSVer);
|
||||
|
||||
typedef OSVersion GCCVersion;
|
||||
#define parseGCCVersion parseOSVersion
|
||||
static const auto &parseGCCVersion = parseOSVersion;
|
||||
|
||||
typedef OSVersion ClangVersion;
|
||||
#define parseClangVersion parseOSVersion
|
||||
static const auto &parseClangVersion = parseOSVersion;
|
||||
|
||||
typedef OSVersion LLVMVersion;
|
||||
static const auto &parseLLVMVersion = parseOSVersion;
|
||||
|
||||
//
|
||||
// OS Compat
|
||||
|
@ -46,6 +46,7 @@
|
||||
<File Name="programs/osxcross-cmp.cpp"/>
|
||||
<File Name="programs/xcrun.cpp"/>
|
||||
<File Name="programs/osxcross-man.cpp"/>
|
||||
<File Name="programs/dsymutil.cpp"/>
|
||||
</VirtualDirectory>
|
||||
<File Name="Makefile"/>
|
||||
<File Name="build.sh"/>
|
||||
|
Loading…
Reference in New Issue
Block a user