2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBFileSpec.cpp ------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-04-19 11:09:28 +08:00
|
|
|
#include <inttypes.h> // PRIu64
|
2011-04-08 21:36:44 +08:00
|
|
|
#include <limits.h>
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/API/SBFileSpec.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2011-02-08 13:05:52 +08:00
|
|
|
#include "lldb/Host/FileSpec.h"
|
2010-10-26 11:11:13 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2011-11-13 14:57:31 +08:00
|
|
|
#include "lldb/Core/Stream.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2014-08-08 01:33:36 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SBFileSpec::SBFileSpec () :
|
Added a way to extract the module specifications from a file. A module specification is information that is required to describe a module (executable, shared library, object file, ect). This information includes host path, platform path (remote path), symbol file path, UUID, object name (for objects in .a files for example you could have an object name of "foo.o"), and target triple. Module specification can be used to create a module, or used to add a module to a target. A list of module specifications can be used to enumerate objects in container objects (like universal mach files and BSD archive files).
There are two new classes:
lldb::SBModuleSpec
lldb::SBModuleSpecList
The SBModuleSpec wraps up a lldb_private::ModuleSpec, and SBModuleSpecList wraps up a lldb_private::ModuleSpecList.
llvm-svn: 185877
2013-07-09 06:22:41 +08:00
|
|
|
m_opaque_ap(new lldb_private::FileSpec())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBFileSpec::SBFileSpec (const SBFileSpec &rhs) :
|
Added a way to extract the module specifications from a file. A module specification is information that is required to describe a module (executable, shared library, object file, ect). This information includes host path, platform path (remote path), symbol file path, UUID, object name (for objects in .a files for example you could have an object name of "foo.o"), and target triple. Module specification can be used to create a module, or used to add a module to a target. A list of module specifications can be used to enumerate objects in container objects (like universal mach files and BSD archive files).
There are two new classes:
lldb::SBModuleSpec
lldb::SBModuleSpecList
The SBModuleSpec wraps up a lldb_private::ModuleSpec, and SBModuleSpecList wraps up a lldb_private::ModuleSpecList.
llvm-svn: 185877
2013-07-09 06:22:41 +08:00
|
|
|
m_opaque_ap(new lldb_private::FileSpec(*rhs.m_opaque_ap))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
Added a way to extract the module specifications from a file. A module specification is information that is required to describe a module (executable, shared library, object file, ect). This information includes host path, platform path (remote path), symbol file path, UUID, object name (for objects in .a files for example you could have an object name of "foo.o"), and target triple. Module specification can be used to create a module, or used to add a module to a target. A list of module specifications can be used to enumerate objects in container objects (like universal mach files and BSD archive files).
There are two new classes:
lldb::SBModuleSpec
lldb::SBModuleSpecList
The SBModuleSpec wraps up a lldb_private::ModuleSpec, and SBModuleSpecList wraps up a lldb_private::ModuleSpecList.
llvm-svn: 185877
2013-07-09 06:22:41 +08:00
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
Added a way to extract the module specifications from a file. A module specification is information that is required to describe a module (executable, shared library, object file, ect). This information includes host path, platform path (remote path), symbol file path, UUID, object name (for objects in .a files for example you could have an object name of "foo.o"), and target triple. Module specification can be used to create a module, or used to add a module to a target. A list of module specifications can be used to enumerate objects in container objects (like universal mach files and BSD archive files).
There are two new classes:
lldb::SBModuleSpec
lldb::SBModuleSpecList
The SBModuleSpec wraps up a lldb_private::ModuleSpec, and SBModuleSpecList wraps up a lldb_private::ModuleSpecList.
llvm-svn: 185877
2013-07-09 06:22:41 +08:00
|
|
|
SBFileSpec::SBFileSpec (const lldb_private::FileSpec& fspec) :
|
|
|
|
m_opaque_ap(new lldb_private::FileSpec(fspec))
|
|
|
|
{
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2014-07-02 05:22:11 +08:00
|
|
|
// Deprecated!!!
|
2010-06-09 00:52:24 +08:00
|
|
|
SBFileSpec::SBFileSpec (const char *path) :
|
2010-10-21 04:54:39 +08:00
|
|
|
m_opaque_ap(new FileSpec (path, true))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBFileSpec::SBFileSpec (const char *path, bool resolve) :
|
|
|
|
m_opaque_ap(new FileSpec (path, resolve))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBFileSpec::~SBFileSpec ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const SBFileSpec &
|
|
|
|
SBFileSpec::operator = (const SBFileSpec &rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
Added a way to extract the module specifications from a file. A module specification is information that is required to describe a module (executable, shared library, object file, ect). This information includes host path, platform path (remote path), symbol file path, UUID, object name (for objects in .a files for example you could have an object name of "foo.o"), and target triple. Module specification can be used to create a module, or used to add a module to a target. A list of module specifications can be used to enumerate objects in container objects (like universal mach files and BSD archive files).
There are two new classes:
lldb::SBModuleSpec
lldb::SBModuleSpecList
The SBModuleSpec wraps up a lldb_private::ModuleSpec, and SBModuleSpecList wraps up a lldb_private::ModuleSpecList.
llvm-svn: 185877
2013-07-09 06:22:41 +08:00
|
|
|
*m_opaque_ap = *rhs.m_opaque_ap;
|
2010-06-09 00:52:24 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBFileSpec::IsValid() const
|
|
|
|
{
|
2013-10-05 05:35:29 +08:00
|
|
|
return m_opaque_ap->operator bool();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBFileSpec::Exists () const
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
Added a way to extract the module specifications from a file. A module specification is information that is required to describe a module (executable, shared library, object file, ect). This information includes host path, platform path (remote path), symbol file path, UUID, object name (for objects in .a files for example you could have an object name of "foo.o"), and target triple. Module specification can be used to create a module, or used to add a module to a target. A list of module specifications can be used to enumerate objects in container objects (like universal mach files and BSD archive files).
There are two new classes:
lldb::SBModuleSpec
lldb::SBModuleSpecList
The SBModuleSpec wraps up a lldb_private::ModuleSpec, and SBModuleSpecList wraps up a lldb_private::ModuleSpecList.
llvm-svn: 185877
2013-07-09 06:22:41 +08:00
|
|
|
bool result = m_opaque_ap->Exists();
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBFileSpec(%p)::Exists () => %s",
|
|
|
|
static_cast<void*>(m_opaque_ap.get()),
|
|
|
|
(result ? "true" : "false"));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return result;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-09-10 12:48:55 +08:00
|
|
|
bool
|
|
|
|
SBFileSpec::ResolveExecutableLocation ()
|
|
|
|
{
|
Added a way to extract the module specifications from a file. A module specification is information that is required to describe a module (executable, shared library, object file, ect). This information includes host path, platform path (remote path), symbol file path, UUID, object name (for objects in .a files for example you could have an object name of "foo.o"), and target triple. Module specification can be used to create a module, or used to add a module to a target. A list of module specifications can be used to enumerate objects in container objects (like universal mach files and BSD archive files).
There are two new classes:
lldb::SBModuleSpec
lldb::SBModuleSpecList
The SBModuleSpec wraps up a lldb_private::ModuleSpec, and SBModuleSpecList wraps up a lldb_private::ModuleSpecList.
llvm-svn: 185877
2013-07-09 06:22:41 +08:00
|
|
|
return m_opaque_ap->ResolveExecutableLocation ();
|
2010-09-10 12:48:55 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
SBFileSpec::ResolvePath (const char *src_path, char *dst_path, size_t dst_len)
|
|
|
|
{
|
2014-08-08 01:33:36 +08:00
|
|
|
llvm::SmallString<64> result(src_path);
|
|
|
|
lldb_private::FileSpec::Resolve (result);
|
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
|
|
|
::snprintf(dst_path, dst_len, "%s", result.c_str());
|
|
|
|
return std::min(dst_len-1, result.size());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2010-08-28 06:35:26 +08:00
|
|
|
SBFileSpec::GetFilename() const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
Added a way to extract the module specifications from a file. A module specification is information that is required to describe a module (executable, shared library, object file, ect). This information includes host path, platform path (remote path), symbol file path, UUID, object name (for objects in .a files for example you could have an object name of "foo.o"), and target triple. Module specification can be used to create a module, or used to add a module to a target. A list of module specifications can be used to enumerate objects in container objects (like universal mach files and BSD archive files).
There are two new classes:
lldb::SBModuleSpec
lldb::SBModuleSpecList
The SBModuleSpec wraps up a lldb_private::ModuleSpec, and SBModuleSpecList wraps up a lldb_private::ModuleSpecList.
llvm-svn: 185877
2013-07-09 06:22:41 +08:00
|
|
|
const char *s = m_opaque_ap->GetFilename().AsCString();
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
if (log)
|
2010-10-31 11:01:06 +08:00
|
|
|
{
|
|
|
|
if (s)
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBFileSpec(%p)::GetFilename () => \"%s\"",
|
|
|
|
static_cast<void*>(m_opaque_ap.get()), s);
|
2010-10-31 11:01:06 +08:00
|
|
|
else
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBFileSpec(%p)::GetFilename () => NULL",
|
|
|
|
static_cast<void*>(m_opaque_ap.get()));
|
2010-10-31 11:01:06 +08:00
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-10-30 12:51:46 +08:00
|
|
|
return s;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBFileSpec::GetDirectory() const
|
|
|
|
{
|
2015-06-09 06:12:58 +08:00
|
|
|
FileSpec directory{*m_opaque_ap};
|
|
|
|
directory.GetFilename().Clear();
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-30 12:51:46 +08:00
|
|
|
if (log)
|
2010-10-31 11:01:06 +08:00
|
|
|
{
|
2015-06-09 06:12:58 +08:00
|
|
|
if (directory)
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBFileSpec(%p)::GetDirectory () => \"%s\"",
|
2015-06-09 06:12:58 +08:00
|
|
|
static_cast<void*>(m_opaque_ap.get()), directory.GetCString());
|
2010-10-31 11:01:06 +08:00
|
|
|
else
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBFileSpec(%p)::GetDirectory () => NULL",
|
|
|
|
static_cast<void*>(m_opaque_ap.get()));
|
2010-10-31 11:01:06 +08:00
|
|
|
}
|
2015-06-09 06:12:58 +08:00
|
|
|
return directory.GetCString();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2013-11-21 05:07:01 +08:00
|
|
|
void
|
|
|
|
SBFileSpec::SetFilename(const char *filename)
|
|
|
|
{
|
|
|
|
if (filename && filename[0])
|
|
|
|
m_opaque_ap->GetFilename().SetCString(filename);
|
|
|
|
else
|
|
|
|
m_opaque_ap->GetFilename().Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBFileSpec::SetDirectory(const char *directory)
|
|
|
|
{
|
|
|
|
if (directory && directory[0])
|
|
|
|
m_opaque_ap->GetDirectory().SetCString(directory);
|
|
|
|
else
|
|
|
|
m_opaque_ap->GetDirectory().Clear();
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t
|
|
|
|
SBFileSpec::GetPath (char *dst_path, size_t dst_len) const
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
Added a way to extract the module specifications from a file. A module specification is information that is required to describe a module (executable, shared library, object file, ect). This information includes host path, platform path (remote path), symbol file path, UUID, object name (for objects in .a files for example you could have an object name of "foo.o"), and target triple. Module specification can be used to create a module, or used to add a module to a target. A list of module specifications can be used to enumerate objects in container objects (like universal mach files and BSD archive files).
There are two new classes:
lldb::SBModuleSpec
lldb::SBModuleSpecList
The SBModuleSpec wraps up a lldb_private::ModuleSpec, and SBModuleSpecList wraps up a lldb_private::ModuleSpecList.
llvm-svn: 185877
2013-07-09 06:22:41 +08:00
|
|
|
uint32_t result = m_opaque_ap->GetPath (dst_path, dst_len);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2012-11-30 05:49:15 +08:00
|
|
|
log->Printf ("SBFileSpec(%p)::GetPath (dst_path=\"%.*s\", dst_len=%" PRIu64 ") => %u",
|
2014-04-04 12:06:10 +08:00
|
|
|
static_cast<void*>(m_opaque_ap.get()), result, dst_path,
|
|
|
|
static_cast<uint64_t>(dst_len), result);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-10-31 11:01:06 +08:00
|
|
|
if (result == 0 && dst_path && dst_len > 0)
|
2010-06-09 00:52:24 +08:00
|
|
|
*dst_path = '\0';
|
2010-10-31 11:01:06 +08:00
|
|
|
return result;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const lldb_private::FileSpec *
|
|
|
|
SBFileSpec::operator->() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const lldb_private::FileSpec *
|
|
|
|
SBFileSpec::get() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const lldb_private::FileSpec &
|
|
|
|
SBFileSpec::operator*() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return *m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const lldb_private::FileSpec &
|
|
|
|
SBFileSpec::ref() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return *m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
|
|
|
|
{
|
Added a way to extract the module specifications from a file. A module specification is information that is required to describe a module (executable, shared library, object file, ect). This information includes host path, platform path (remote path), symbol file path, UUID, object name (for objects in .a files for example you could have an object name of "foo.o"), and target triple. Module specification can be used to create a module, or used to add a module to a target. A list of module specifications can be used to enumerate objects in container objects (like universal mach files and BSD archive files).
There are two new classes:
lldb::SBModuleSpec
lldb::SBModuleSpecList
The SBModuleSpec wraps up a lldb_private::ModuleSpec, and SBModuleSpecList wraps up a lldb_private::ModuleSpecList.
llvm-svn: 185877
2013-07-09 06:22:41 +08:00
|
|
|
*m_opaque_ap = fs;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-10-26 11:11:13 +08:00
|
|
|
bool
|
|
|
|
SBFileSpec::GetDescription (SBStream &description) const
|
|
|
|
{
|
2011-11-13 14:57:31 +08:00
|
|
|
Stream &strm = description.ref();
|
Added a way to extract the module specifications from a file. A module specification is information that is required to describe a module (executable, shared library, object file, ect). This information includes host path, platform path (remote path), symbol file path, UUID, object name (for objects in .a files for example you could have an object name of "foo.o"), and target triple. Module specification can be used to create a module, or used to add a module to a target. A list of module specifications can be used to enumerate objects in container objects (like universal mach files and BSD archive files).
There are two new classes:
lldb::SBModuleSpec
lldb::SBModuleSpecList
The SBModuleSpec wraps up a lldb_private::ModuleSpec, and SBModuleSpecList wraps up a lldb_private::ModuleSpecList.
llvm-svn: 185877
2013-07-09 06:22:41 +08:00
|
|
|
char path[PATH_MAX];
|
|
|
|
if (m_opaque_ap->GetPath(path, sizeof(path)))
|
|
|
|
strm.PutCString (path);
|
2010-10-26 11:11:13 +08:00
|
|
|
return true;
|
|
|
|
}
|
2016-02-19 08:05:17 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
SBFileSpec::AppendPathComponent (const char *fn)
|
|
|
|
{
|
|
|
|
m_opaque_ap->AppendPathComponent (fn);
|
|
|
|
}
|