2014-08-20 01:18:29 +08:00
|
|
|
//===-- HostInfoMacOSX.mm ---------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-22 01:29:12 +08:00
|
|
|
#include "lldb/lldb-python.h"
|
|
|
|
|
|
|
|
#include "lldb/Host/HostInfo.h"
|
2014-08-20 01:18:29 +08:00
|
|
|
#include "lldb/Host/macosx/HostInfoMacOSX.h"
|
|
|
|
#include "lldb/Interpreter/Args.h"
|
2014-08-21 00:42:51 +08:00
|
|
|
#include "lldb/Utility/SafeMachO.h"
|
|
|
|
|
2014-08-22 01:29:12 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
2014-08-20 01:18:29 +08:00
|
|
|
// C++ Includes
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
// C inclues
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
// Objective C/C++ includes
|
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
|
|
#include <Foundation/Foundation.h>
|
2014-08-22 05:49:24 +08:00
|
|
|
#include <mach-o/dyld.h>
|
2014-08-20 01:18:29 +08:00
|
|
|
#include <objc/objc-auto.h>
|
|
|
|
|
2014-08-24 05:40:29 +08:00
|
|
|
// These are needed when compiling on systems
|
|
|
|
// that do not yet have these definitions
|
|
|
|
#include <AvailabilityMacros.h>
|
|
|
|
#ifndef CPU_SUBTYPE_X86_64_H
|
|
|
|
#define CPU_SUBTYPE_X86_64_H ((cpu_subtype_t)8)
|
|
|
|
#endif
|
|
|
|
#ifndef CPU_TYPE_ARM64
|
|
|
|
#define CPU_TYPE_ARM64 (CPU_TYPE_ARM|CPU_ARCH_ABI64)
|
|
|
|
#endif
|
|
|
|
|
2014-08-20 01:18:29 +08:00
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
bool
|
|
|
|
HostInfoMacOSX::GetOSBuildString(std::string &s)
|
|
|
|
{
|
|
|
|
int mib[2] = {CTL_KERN, KERN_OSVERSION};
|
|
|
|
char cstr[PATH_MAX];
|
|
|
|
size_t cstr_len = sizeof(cstr);
|
|
|
|
if (::sysctl(mib, 2, cstr, &cstr_len, NULL, 0) == 0)
|
|
|
|
{
|
|
|
|
s.assign(cstr, cstr_len);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
s.clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HostInfoMacOSX::GetOSKernelDescription(std::string &s)
|
|
|
|
{
|
|
|
|
int mib[2] = {CTL_KERN, KERN_VERSION};
|
|
|
|
char cstr[PATH_MAX];
|
|
|
|
size_t cstr_len = sizeof(cstr);
|
|
|
|
if (::sysctl(mib, 2, cstr, &cstr_len, NULL, 0) == 0)
|
|
|
|
{
|
|
|
|
s.assign(cstr, cstr_len);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
s.clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HostInfoMacOSX::GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update)
|
|
|
|
{
|
|
|
|
static uint32_t g_major = 0;
|
|
|
|
static uint32_t g_minor = 0;
|
|
|
|
static uint32_t g_update = 0;
|
|
|
|
|
|
|
|
if (g_major == 0)
|
|
|
|
{
|
|
|
|
@autoreleasepool
|
|
|
|
{
|
|
|
|
NSDictionary *version_info = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
|
|
|
|
NSString *version_value = [version_info objectForKey:@"ProductVersion"];
|
|
|
|
const char *version_str = [version_value UTF8String];
|
|
|
|
if (version_str)
|
|
|
|
Args::StringToVersion(version_str, g_major, g_minor, g_update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_major != 0)
|
|
|
|
{
|
|
|
|
major = g_major;
|
|
|
|
minor = g_minor;
|
|
|
|
update = g_update;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-08-21 00:42:51 +08:00
|
|
|
|
2014-08-22 05:49:24 +08:00
|
|
|
FileSpec
|
|
|
|
HostInfoMacOSX::GetProgramFileSpec()
|
|
|
|
{
|
|
|
|
static FileSpec g_program_filespec;
|
|
|
|
if (!g_program_filespec)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return g_program_filespec;
|
|
|
|
}
|
|
|
|
|
2014-08-22 01:29:12 +08:00
|
|
|
bool
|
|
|
|
HostInfoMacOSX::ComputeSupportExeDirectory(FileSpec &file_spec)
|
|
|
|
{
|
|
|
|
FileSpec lldb_file_spec;
|
|
|
|
if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
|
|
|
|
return false;
|
|
|
|
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
std::string raw_path = lldb_file_spec.GetPath();
|
|
|
|
|
|
|
|
size_t framework_pos = raw_path.find("LLDB.framework");
|
|
|
|
if (framework_pos != std::string::npos)
|
2014-08-22 01:29:12 +08:00
|
|
|
{
|
|
|
|
framework_pos += strlen("LLDB.framework");
|
|
|
|
#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
|
|
|
|
// Shallow bundle
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
raw_path.resize(framework_pos);
|
2014-08-22 01:29:12 +08:00
|
|
|
#else
|
|
|
|
// Normal bundle
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
raw_path.resize(framework_pos);
|
|
|
|
raw_path.append("/Resources");
|
2014-08-22 01:29:12 +08:00
|
|
|
#endif
|
|
|
|
}
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
file_spec.GetDirectory().SetString(llvm::StringRef(raw_path.c_str(), raw_path.size()));
|
2014-08-22 01:29:12 +08:00
|
|
|
return (bool)file_spec.GetDirectory();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HostInfoMacOSX::ComputeHeaderDirectory(FileSpec &file_spec)
|
|
|
|
{
|
|
|
|
FileSpec lldb_file_spec;
|
|
|
|
if (!HostInfo::GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
|
|
|
|
return false;
|
|
|
|
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
std::string raw_path = lldb_file_spec.GetPath();
|
2014-08-22 01:29:12 +08:00
|
|
|
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
size_t framework_pos = raw_path.find("LLDB.framework");
|
|
|
|
if (framework_pos != std::string::npos)
|
2014-08-22 01:29:12 +08:00
|
|
|
{
|
|
|
|
framework_pos += strlen("LLDB.framework");
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
raw_path.resize(framework_pos);
|
|
|
|
raw_path.append("/Headers");
|
2014-08-22 01:29:12 +08:00
|
|
|
}
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
file_spec.GetDirectory().SetString(llvm::StringRef(raw_path.c_str(), raw_path.size()));
|
2014-08-22 01:29:12 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HostInfoMacOSX::ComputePythonDirectory(FileSpec &file_spec)
|
|
|
|
{
|
2014-09-09 12:52:37 +08:00
|
|
|
#ifndef LLDB_DISABLE_PYTHON
|
2014-08-22 01:29:12 +08:00
|
|
|
FileSpec lldb_file_spec;
|
|
|
|
if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
|
|
|
|
return false;
|
|
|
|
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
std::string raw_path = lldb_file_spec.GetPath();
|
2014-08-22 01:29:12 +08:00
|
|
|
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
size_t framework_pos = raw_path.find("LLDB.framework");
|
|
|
|
if (framework_pos != std::string::npos)
|
2014-08-22 01:29:12 +08:00
|
|
|
{
|
|
|
|
framework_pos += strlen("LLDB.framework");
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
raw_path.resize(framework_pos);
|
|
|
|
raw_path.append("/Resources/Python");
|
2014-08-22 01:29:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
llvm::SmallString<256> python_version_dir;
|
|
|
|
llvm::raw_svector_ostream os(python_version_dir);
|
|
|
|
os << "/python" << PY_MAJOR_VERSION << '.' << PY_MINOR_VERSION << "/site-packages";
|
|
|
|
os.flush();
|
|
|
|
|
|
|
|
// We may get our string truncated. Should we protect this with an assert?
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
raw_path.append(python_version_dir.c_str());
|
2014-08-22 01:29:12 +08:00
|
|
|
}
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
file_spec.GetDirectory().SetString(llvm::StringRef(raw_path.c_str(), raw_path.size()));
|
2014-09-09 12:56:16 +08:00
|
|
|
return true;
|
2014-09-09 12:52:37 +08:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2014-08-22 01:29:12 +08:00
|
|
|
}
|
|
|
|
|
2014-12-05 09:15:04 +08:00
|
|
|
bool
|
|
|
|
HostInfoMacOSX::ComputeClangDirectory(FileSpec &file_spec)
|
|
|
|
{
|
|
|
|
FileSpec lldb_file_spec;
|
|
|
|
if (!GetLLDBPath (lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
|
|
|
|
return false;
|
|
|
|
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
std::string raw_path = lldb_file_spec.GetPath();
|
2014-12-05 09:15:04 +08:00
|
|
|
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
size_t framework_pos = raw_path.find("LLDB.framework");
|
|
|
|
if (framework_pos != std::string::npos)
|
2014-12-05 09:15:04 +08:00
|
|
|
{
|
|
|
|
framework_pos += strlen("LLDB.framework");
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
raw_path.resize(framework_pos);
|
|
|
|
raw_path.append("/Resources/Clang");
|
2014-12-05 09:15:04 +08:00
|
|
|
}
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
file_spec.SetFile (raw_path.c_str(), true);
|
2014-12-05 09:15:04 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-22 01:29:12 +08:00
|
|
|
bool
|
|
|
|
HostInfoMacOSX::ComputeSystemPluginsDirectory(FileSpec &file_spec)
|
|
|
|
{
|
|
|
|
FileSpec lldb_file_spec;
|
|
|
|
if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
|
|
|
|
return false;
|
|
|
|
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
std::string raw_path = lldb_file_spec.GetPath();
|
|
|
|
|
|
|
|
size_t framework_pos = raw_path.find("LLDB.framework");
|
|
|
|
if (framework_pos == std::string::npos)
|
2014-08-22 01:29:12 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
framework_pos += strlen("LLDB.framework");
|
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
2015-02-28 03:43:08 +08:00
|
|
|
raw_path.resize(framework_pos);
|
|
|
|
raw_path.append("/Resources/PlugIns");
|
|
|
|
file_spec.GetDirectory().SetString(llvm::StringRef(raw_path.c_str(), raw_path.size()));
|
2014-08-22 01:29:12 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HostInfoMacOSX::ComputeUserPluginsDirectory(FileSpec &file_spec)
|
|
|
|
{
|
2014-08-26 02:21:06 +08:00
|
|
|
FileSpec temp_file("~/Library/Application Support/LLDB/PlugIns", true);
|
|
|
|
file_spec.GetDirectory().SetCString(temp_file.GetPath().c_str());
|
2014-08-22 01:29:12 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-21 00:42:51 +08:00
|
|
|
void
|
|
|
|
HostInfoMacOSX::ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64)
|
|
|
|
{
|
|
|
|
// All apple systems support 32 bit execution.
|
|
|
|
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);
|
|
|
|
::sysctlbyname("hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0);
|
|
|
|
|
|
|
|
if (is_64_bit_capable)
|
|
|
|
{
|
|
|
|
if (cputype & CPU_ARCH_ABI64)
|
|
|
|
{
|
|
|
|
// We have a 64 bit kernel on a 64 bit system
|
|
|
|
arch_64.SetArchitecture(eArchTypeMachO, cputype, cpusubtype);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We have a 64 bit kernel that is returning a 32 bit cputype, the
|
|
|
|
// cpusubtype will be correct as if it were for a 64 bit architecture
|
|
|
|
arch_64.SetArchitecture(eArchTypeMachO, cputype | CPU_ARCH_ABI64, cpusubtype);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we need modify the cpusubtype for the 32 bit slices.
|
|
|
|
uint32_t cpusubtype32 = cpusubtype;
|
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
|
|
|
if (cpusubtype == CPU_SUBTYPE_486 || cpusubtype == CPU_SUBTYPE_X86_64_H)
|
|
|
|
cpusubtype32 = CPU_SUBTYPE_I386_ALL;
|
|
|
|
#elif defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
|
|
|
|
if (cputype == CPU_TYPE_ARM || cputype == CPU_TYPE_ARM64)
|
|
|
|
cpusubtype32 = CPU_SUBTYPE_ARM_V7S;
|
|
|
|
#endif
|
|
|
|
arch_32.SetArchitecture(eArchTypeMachO, cputype & ~(CPU_ARCH_MASK), cpusubtype32);
|
|
|
|
|
|
|
|
if (cputype == CPU_TYPE_ARM || cputype == CPU_TYPE_ARM64)
|
|
|
|
{
|
|
|
|
arch_32.GetTriple().setOS(llvm::Triple::IOS);
|
|
|
|
arch_64.GetTriple().setOS(llvm::Triple::IOS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
arch_32.GetTriple().setOS(llvm::Triple::MacOSX);
|
|
|
|
arch_64.GetTriple().setOS(llvm::Triple::MacOSX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We have a 32 bit kernel on a 32 bit system
|
|
|
|
arch_32.SetArchitecture(eArchTypeMachO, cputype, cpusubtype);
|
|
|
|
arch_64.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|