summaryrefslogtreecommitdiff
path: root/source/Utility
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2015-07-03 16:57:06 +0000
committerEd Maste <emaste@FreeBSD.org>2015-07-03 16:57:06 +0000
commit5e95aa85bb660d45e9905ef1d7180b2678280660 (patch)
tree3c2e41c3be19b7fc7666ed45a5f91ec3b6e35f2a /source/Utility
parent12bd4897ff0678fa663e09d78ebc22dd255ceb86 (diff)
Notes
Diffstat (limited to 'source/Utility')
-rw-r--r--source/Utility/ConvertEnum.cpp110
-rw-r--r--source/Utility/JSON.cpp217
-rw-r--r--source/Utility/LLDBAssert.cpp36
-rw-r--r--source/Utility/ModuleCache.cpp186
-rw-r--r--source/Utility/ModuleCache.h78
-rw-r--r--source/Utility/NameMatches.cpp50
-rw-r--r--source/Utility/PseudoTerminal.cpp12
-rw-r--r--source/Utility/StringExtractor.cpp4
-rw-r--r--source/Utility/StringExtractorGDBRemote.cpp13
-rw-r--r--source/Utility/StringExtractorGDBRemote.h4
-rw-r--r--source/Utility/UriParser.cpp1
11 files changed, 706 insertions, 5 deletions
diff --git a/source/Utility/ConvertEnum.cpp b/source/Utility/ConvertEnum.cpp
new file mode 100644
index 0000000000000..e108f5e75420c
--- /dev/null
+++ b/source/Utility/ConvertEnum.cpp
@@ -0,0 +1,110 @@
+//===-- ConvertEnum.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/Utility/ConvertEnum.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+const char *
+lldb_private::GetVoteAsCString(Vote vote)
+{
+ switch (vote)
+ {
+ case eVoteNo:
+ return "no";
+ case eVoteNoOpinion:
+ return "no opinion";
+ case eVoteYes:
+ return "yes";
+ }
+ return "invalid";
+}
+
+const char *
+lldb_private::GetSectionTypeAsCString(lldb::SectionType sect_type)
+{
+ switch (sect_type)
+ {
+ case eSectionTypeInvalid:
+ return "invalid";
+ case eSectionTypeCode:
+ return "code";
+ case eSectionTypeContainer:
+ return "container";
+ case eSectionTypeData:
+ return "data";
+ case eSectionTypeDataCString:
+ return "data-cstr";
+ case eSectionTypeDataCStringPointers:
+ return "data-cstr-ptr";
+ case eSectionTypeDataSymbolAddress:
+ return "data-symbol-addr";
+ case eSectionTypeData4:
+ return "data-4-byte";
+ case eSectionTypeData8:
+ return "data-8-byte";
+ case eSectionTypeData16:
+ return "data-16-byte";
+ case eSectionTypeDataPointers:
+ return "data-ptrs";
+ case eSectionTypeDebug:
+ return "debug";
+ case eSectionTypeZeroFill:
+ return "zero-fill";
+ case eSectionTypeDataObjCMessageRefs:
+ return "objc-message-refs";
+ case eSectionTypeDataObjCCFStrings:
+ return "objc-cfstrings";
+ case eSectionTypeDWARFDebugAbbrev:
+ return "dwarf-abbrev";
+ case eSectionTypeDWARFDebugAranges:
+ return "dwarf-aranges";
+ case eSectionTypeDWARFDebugFrame:
+ return "dwarf-frame";
+ case eSectionTypeDWARFDebugInfo:
+ return "dwarf-info";
+ case eSectionTypeDWARFDebugLine:
+ return "dwarf-line";
+ case eSectionTypeDWARFDebugLoc:
+ return "dwarf-loc";
+ case eSectionTypeDWARFDebugMacInfo:
+ return "dwarf-macinfo";
+ case eSectionTypeDWARFDebugPubNames:
+ return "dwarf-pubnames";
+ case eSectionTypeDWARFDebugPubTypes:
+ return "dwarf-pubtypes";
+ case eSectionTypeDWARFDebugRanges:
+ return "dwarf-ranges";
+ case eSectionTypeDWARFDebugStr:
+ return "dwarf-str";
+ case eSectionTypeELFSymbolTable:
+ return "elf-symbol-table";
+ case eSectionTypeELFDynamicSymbols:
+ return "elf-dynamic-symbols";
+ case eSectionTypeELFRelocationEntries:
+ return "elf-relocation-entries";
+ case eSectionTypeELFDynamicLinkInfo:
+ return "elf-dynamic-link-info";
+ case eSectionTypeDWARFAppleNames:
+ return "apple-names";
+ case eSectionTypeDWARFAppleTypes:
+ return "apple-types";
+ case eSectionTypeDWARFAppleNamespaces:
+ return "apple-namespaces";
+ case eSectionTypeDWARFAppleObjC:
+ return "apple-objc";
+ case eSectionTypeEHFrame:
+ return "eh-frame";
+ case eSectionTypeCompactUnwind:
+ return "compact-unwind";
+ case eSectionTypeOther:
+ return "regular";
+ }
+ return "unknown";
+}
diff --git a/source/Utility/JSON.cpp b/source/Utility/JSON.cpp
new file mode 100644
index 0000000000000..0ba8cf4399ce1
--- /dev/null
+++ b/source/Utility/JSON.cpp
@@ -0,0 +1,217 @@
+//===--------------------- JSON.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/Utility/JSON.h"
+
+using namespace lldb_private;
+
+std::string
+JSONString::json_string_quote_metachars (const std::string &s)
+{
+ if (s.find('"') == std::string::npos)
+ return s;
+
+ std::string output;
+ const size_t s_size = s.size();
+ const char *s_chars = s.c_str();
+ for (size_t i = 0; i < s_size; i++)
+ {
+ unsigned char ch = *(s_chars + i);
+ if (ch == '"')
+ {
+ output.push_back ('\\');
+ }
+ output.push_back (ch);
+ }
+ return output;
+}
+
+JSONString::JSONString () :
+JSONValue(JSONValue::Kind::String),
+m_data()
+{
+}
+
+JSONString::JSONString (const char* s) :
+JSONValue(JSONValue::Kind::String),
+m_data(s ? s : "")
+{
+}
+
+JSONString::JSONString (const std::string& s) :
+JSONValue(JSONValue::Kind::String),
+m_data(s)
+{
+}
+
+void
+JSONString::Write (Stream& s)
+{
+ s.Printf("\"%s\"", json_string_quote_metachars(m_data).c_str());
+}
+
+JSONNumber::JSONNumber () :
+JSONValue(JSONValue::Kind::Number),
+m_data(0)
+{
+}
+
+JSONNumber::JSONNumber (int64_t i) :
+JSONValue(JSONValue::Kind::Number),
+m_data(i)
+{
+}
+
+void
+JSONNumber::Write (Stream& s)
+{
+ s.Printf("%" PRId64, m_data);
+}
+
+JSONTrue::JSONTrue () :
+JSONValue(JSONValue::Kind::True)
+{
+}
+
+void
+JSONTrue::Write(Stream& s)
+{
+ s.Printf("true");
+}
+
+JSONFalse::JSONFalse () :
+JSONValue(JSONValue::Kind::False)
+{
+}
+
+void
+JSONFalse::Write(Stream& s)
+{
+ s.Printf("false");
+}
+
+JSONNull::JSONNull () :
+JSONValue(JSONValue::Kind::Null)
+{
+}
+
+void
+JSONNull::Write(Stream& s)
+{
+ s.Printf("null");
+}
+
+JSONObject::JSONObject () :
+JSONValue(JSONValue::Kind::Object)
+{
+}
+
+void
+JSONObject::Write (Stream& s)
+{
+ bool first = true;
+ s.PutChar('{');
+ auto iter = m_elements.begin(), end = m_elements.end();
+ for (;iter != end; iter++)
+ {
+ if (first)
+ first = false;
+ else
+ s.PutChar(',');
+ JSONString key(iter->first);
+ JSONValue::SP value(iter->second);
+ key.Write(s);
+ s.PutChar(':');
+ value->Write(s);
+ }
+ s.PutChar('}');
+}
+
+bool
+JSONObject::SetObject (const std::string& key,
+ JSONValue::SP value)
+{
+ if (key.empty() || nullptr == value.get())
+ return false;
+ m_elements[key] = value;
+ return true;
+}
+
+JSONValue::SP
+JSONObject::GetObject (const std::string& key)
+{
+ auto iter = m_elements.find(key), end = m_elements.end();
+ if (iter == end)
+ return JSONValue::SP();
+ return iter->second;
+}
+
+JSONArray::JSONArray () :
+JSONValue(JSONValue::Kind::Array)
+{
+}
+
+void
+JSONArray::Write (Stream& s)
+{
+ bool first = true;
+ s.PutChar('[');
+ auto iter = m_elements.begin(), end = m_elements.end();
+ for (;iter != end; iter++)
+ {
+ if (first)
+ first = false;
+ else
+ s.PutChar(',');
+ (*iter)->Write(s);
+ }
+ s.PutChar(']');
+}
+
+bool
+JSONArray::SetObject (Index i,
+ JSONValue::SP value)
+{
+ if (value.get() == nullptr)
+ return false;
+ if (i < m_elements.size())
+ {
+ m_elements[i] = value;
+ return true;
+ }
+ if (i == m_elements.size())
+ {
+ m_elements.push_back(value);
+ return true;
+ }
+ return false;
+}
+
+bool
+JSONArray::AppendObject (JSONValue::SP value)
+{
+ if (value.get() == nullptr)
+ return false;
+ m_elements.push_back(value);
+ return true;
+}
+
+JSONValue::SP
+JSONArray::GetObject (Index i)
+{
+ if (i < m_elements.size())
+ return m_elements[i];
+ return JSONValue::SP();
+}
+
+JSONArray::Size
+JSONArray::GetNumElements ()
+{
+ return m_elements.size();
+}
diff --git a/source/Utility/LLDBAssert.cpp b/source/Utility/LLDBAssert.cpp
new file mode 100644
index 0000000000000..68aa872c83cfd
--- /dev/null
+++ b/source/Utility/LLDBAssert.cpp
@@ -0,0 +1,36 @@
+//===--------------------- LLDBAssert.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/Utility/LLDBAssert.h"
+
+#include "llvm/Support/Format.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Signals.h"
+
+using namespace llvm;
+using namespace lldb_private;
+
+void
+lldb_private::lldb_assert (bool expression,
+ const char* expr_text,
+ const char* func,
+ const char* file,
+ unsigned int line)
+{
+ if (expression)
+ ;
+ else
+ {
+ errs() << format("Assertion failed: (%s), function %s, file %s, line %u\n",
+ expr_text, func, file, line);
+ errs() << "backtrace leading to the failure:\n";
+ llvm::sys::PrintStackTrace(errs());
+ errs() << "please file a bug report against lldb reporting this failure log, and as many details as possible\n";
+ }
+}
diff --git a/source/Utility/ModuleCache.cpp b/source/Utility/ModuleCache.cpp
new file mode 100644
index 0000000000000..ce0df241dc226
--- /dev/null
+++ b/source/Utility/ModuleCache.cpp
@@ -0,0 +1,186 @@
+//===--------------------- ModuleCache.cpp ----------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ModuleCache.h"
+
+#include "lldb/Core/Module.h"
+#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Host/File.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/LockFile.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
+
+#include <assert.h>
+
+#include <cstdio>
+
+using namespace lldb;
+using namespace lldb_private;
+
+namespace {
+
+const char* kModulesSubdir = ".cache";
+const char* kLockFileName = ".lock";
+const char* kTempFileName = ".temp";
+
+FileSpec
+JoinPath (const FileSpec &path1, const char* path2)
+{
+ FileSpec result_spec (path1);
+ result_spec.AppendPathComponent (path2);
+ return result_spec;
+}
+
+Error
+MakeDirectory (const FileSpec &dir_path)
+{
+ if (dir_path.Exists ())
+ {
+ if (!dir_path.IsDirectory ())
+ return Error ("Invalid existing path");
+
+ return Error ();
+ }
+
+ return FileSystem::MakeDirectory(dir_path, eFilePermissionsDirectoryDefault);
+}
+
+FileSpec
+GetModuleDirectory (const FileSpec &root_dir_spec, const UUID &uuid)
+{
+ const auto modules_dir_spec = JoinPath (root_dir_spec, kModulesSubdir);
+ return JoinPath (modules_dir_spec, uuid.GetAsString ().c_str ());
+}
+
+Error
+CreateHostSysRootModuleLink (const FileSpec &root_dir_spec, const char *hostname, const FileSpec &platform_module_spec, const FileSpec &local_module_spec)
+{
+ const auto sysroot_module_path_spec = JoinPath (
+ JoinPath (root_dir_spec, hostname), platform_module_spec.GetPath ().c_str ());
+ if (sysroot_module_path_spec.Exists())
+ return Error ();
+
+ const auto error = MakeDirectory (FileSpec (sysroot_module_path_spec.GetDirectory ().AsCString (), false));
+ if (error.Fail ())
+ return error;
+
+ return FileSystem::Hardlink(sysroot_module_path_spec, local_module_spec);
+}
+
+} // namespace
+
+Error
+ModuleCache::Put (const FileSpec &root_dir_spec,
+ const char *hostname,
+ const ModuleSpec &module_spec,
+ const FileSpec &tmp_file)
+{
+ const auto module_spec_dir = GetModuleDirectory (root_dir_spec, module_spec.GetUUID ());
+ const auto module_file_path = JoinPath (module_spec_dir, module_spec.GetFileSpec ().GetFilename ().AsCString ());
+
+ const auto tmp_file_path = tmp_file.GetPath ();
+ const auto err_code = llvm::sys::fs::rename (tmp_file_path.c_str (), module_file_path.GetPath ().c_str ());
+ if (err_code)
+ return Error ("Failed to rename file %s to %s: %s",
+ tmp_file_path.c_str (), module_file_path.GetPath ().c_str (), err_code.message ().c_str ());
+
+ const auto error = CreateHostSysRootModuleLink(root_dir_spec, hostname, module_spec.GetFileSpec(), module_file_path);
+ if (error.Fail ())
+ return Error ("Failed to create link to %s: %s", module_file_path.GetPath ().c_str (), error.AsCString ());
+ return Error ();
+}
+
+Error
+ModuleCache::Get (const FileSpec &root_dir_spec,
+ const char *hostname,
+ const ModuleSpec &module_spec,
+ ModuleSP &cached_module_sp,
+ bool *did_create_ptr)
+{
+ const auto find_it = m_loaded_modules.find (module_spec.GetUUID ().GetAsString());
+ if (find_it != m_loaded_modules.end ())
+ {
+ cached_module_sp = (*find_it).second.lock ();
+ if (cached_module_sp)
+ return Error ();
+ m_loaded_modules.erase (find_it);
+ }
+
+ const auto module_spec_dir = GetModuleDirectory (root_dir_spec, module_spec.GetUUID ());
+ const auto module_file_path = JoinPath (module_spec_dir, module_spec.GetFileSpec ().GetFilename ().AsCString ());
+
+ if (!module_file_path.Exists ())
+ return Error ("Module %s not found", module_file_path.GetPath ().c_str ());
+ if (module_file_path.GetByteSize () != module_spec.GetObjectSize ())
+ return Error ("Module %s has invalid file size", module_file_path.GetPath ().c_str ());
+
+ // We may have already cached module but downloaded from an another host - in this case let's create a link to it.
+ const auto error = CreateHostSysRootModuleLink(root_dir_spec, hostname, module_spec.GetFileSpec(), module_file_path);
+ if (error.Fail ())
+ return Error ("Failed to create link to %s: %s", module_file_path.GetPath().c_str(), error.AsCString());
+
+ auto cached_module_spec (module_spec);
+ cached_module_spec.GetUUID ().Clear (); // Clear UUID since it may contain md5 content hash instead of real UUID.
+ cached_module_spec.GetFileSpec () = module_file_path;
+ cached_module_spec.GetPlatformFileSpec () = module_spec.GetFileSpec ();
+ cached_module_sp.reset (new Module (cached_module_spec));
+ if (did_create_ptr)
+ *did_create_ptr = true;
+
+ m_loaded_modules.insert (std::make_pair (module_spec.GetUUID ().GetAsString (), cached_module_sp));
+
+ return Error ();
+}
+
+Error
+ModuleCache::GetAndPut (const FileSpec &root_dir_spec,
+ const char *hostname,
+ const ModuleSpec &module_spec,
+ const Downloader &downloader,
+ lldb::ModuleSP &cached_module_sp,
+ bool *did_create_ptr)
+{
+ const auto module_spec_dir = GetModuleDirectory (root_dir_spec, module_spec.GetUUID ());
+ auto error = MakeDirectory (module_spec_dir);
+ if (error.Fail ())
+ return error;
+
+ // Open lock file.
+ const auto lock_file_spec = JoinPath (module_spec_dir, kLockFileName);
+ File lock_file (lock_file_spec, File::eOpenOptionWrite | File::eOpenOptionCanCreate | File::eOpenOptionCloseOnExec);
+ if (!lock_file)
+ {
+ error.SetErrorToErrno ();
+ return Error("Failed to open lock file %s: %s", lock_file_spec.GetPath ().c_str (), error.AsCString ());
+ }
+ LockFile lock (lock_file.GetDescriptor ());
+ error = lock.WriteLock (0, 1);
+ if (error.Fail ())
+ return Error("Failed to lock file %s:%s", lock_file_spec.GetPath ().c_str (), error.AsCString ());
+
+ // Check local cache for a module.
+ error = Get (root_dir_spec, hostname, module_spec, cached_module_sp, did_create_ptr);
+ if (error.Success ())
+ return error;
+
+ const auto tmp_download_file_spec = JoinPath (module_spec_dir, kTempFileName);
+ error = downloader (module_spec, tmp_download_file_spec);
+ llvm::FileRemover tmp_file_remover (tmp_download_file_spec.GetPath ().c_str ());
+ if (error.Fail ())
+ return Error("Failed to download module: %s", error.AsCString ());
+
+ // Put downloaded file into local module cache.
+ error = Put (root_dir_spec, hostname, module_spec, tmp_download_file_spec);
+ if (error.Fail ())
+ return Error ("Failed to put module into cache: %s", error.AsCString ());
+
+ tmp_file_remover.releaseFile ();
+ return Get (root_dir_spec, hostname, module_spec, cached_module_sp, did_create_ptr);
+}
diff --git a/source/Utility/ModuleCache.h b/source/Utility/ModuleCache.h
new file mode 100644
index 0000000000000..791e2b35ae3d8
--- /dev/null
+++ b/source/Utility/ModuleCache.h
@@ -0,0 +1,78 @@
+//===-- ModuleCache.h -------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef utility_ModuleCache_h_
+#define utility_ModuleCache_h_
+
+#include "lldb/lldb-types.h"
+#include "lldb/lldb-forward.h"
+
+#include "lldb/Core/Error.h"
+#include "lldb/Host/File.h"
+#include "lldb/Host/FileSpec.h"
+
+#include <functional>
+#include <string>
+#include <unordered_map>
+
+namespace lldb_private {
+
+class Module;
+class UUID;
+
+//----------------------------------------------------------------------
+/// @class ModuleCache ModuleCache.h "Utility/ModuleCache.h"
+/// @brief A module cache class.
+///
+/// Caches locally modules that are downloaded from remote targets.
+/// Each cached module maintains 2 views:
+/// - UUID view: /${CACHE_ROOT}/${PLATFORM_NAME}/.cache/${UUID}/${MODULE_FILENAME}
+/// - Sysroot view: /${CACHE_ROOT}/${PLATFORM_NAME}/${HOSTNAME}/${MODULE_FULL_FILEPATH}
+///
+/// UUID views stores a real module file, whereas Sysroot view holds a symbolic
+/// link to UUID-view file.
+///
+/// Example:
+/// UUID view : /tmp/lldb/remote-linux/.cache/30C94DC6-6A1F-E951-80C3-D68D2B89E576-D5AE213C/libc.so.6
+/// Sysroot view: /tmp/lldb/remote-linux/ubuntu/lib/x86_64-linux-gnu/libc.so.6
+//----------------------------------------------------------------------
+
+class ModuleCache
+{
+public:
+ using Downloader = std::function<Error (const ModuleSpec&, const FileSpec&)>;
+
+ Error
+ GetAndPut(const FileSpec &root_dir_spec,
+ const char *hostname,
+ const ModuleSpec &module_spec,
+ const Downloader &downloader,
+ lldb::ModuleSP &cached_module_sp,
+ bool *did_create_ptr);
+
+private:
+ Error
+ Put (const FileSpec &root_dir_spec,
+ const char *hostname,
+ const ModuleSpec &module_spec,
+ const FileSpec &tmp_file);
+
+ Error
+ Get (const FileSpec &root_dir_spec,
+ const char *hostname,
+ const ModuleSpec &module_spec,
+ lldb::ModuleSP &cached_module_sp,
+ bool *did_create_ptr);
+
+ std::unordered_map<std::string, lldb::ModuleWP> m_loaded_modules;
+};
+
+} // namespace lldb_private
+
+#endif // utility_ModuleCache_h_
diff --git a/source/Utility/NameMatches.cpp b/source/Utility/NameMatches.cpp
new file mode 100644
index 0000000000000..e10c47e4fd9b2
--- /dev/null
+++ b/source/Utility/NameMatches.cpp
@@ -0,0 +1,50 @@
+//===-- NameMatches.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/Core/RegularExpression.h"
+#include "lldb/Utility/NameMatches.h"
+
+#include "llvm/ADT/StringRef.h"
+
+using namespace lldb_private;
+
+bool
+lldb_private::NameMatches(const char *name, NameMatchType match_type, const char *match)
+{
+ if (match_type == eNameMatchIgnore)
+ return true;
+
+ if (name == match)
+ return true;
+
+ if (name && match)
+ {
+ llvm::StringRef name_sref(name);
+ llvm::StringRef match_sref(match);
+ switch (match_type)
+ {
+ case eNameMatchIgnore: // This case cannot occur: tested before
+ return true;
+ case eNameMatchEquals:
+ return name_sref == match_sref;
+ case eNameMatchContains:
+ return name_sref.find(match_sref) != llvm::StringRef::npos;
+ case eNameMatchStartsWith:
+ return name_sref.startswith(match_sref);
+ case eNameMatchEndsWith:
+ return name_sref.endswith(match_sref);
+ case eNameMatchRegularExpression:
+ {
+ RegularExpression regex(match);
+ return regex.Execute(name);
+ }
+ break;
+ }
+ }
+ return false;
+}
diff --git a/source/Utility/PseudoTerminal.cpp b/source/Utility/PseudoTerminal.cpp
index e90955d37d4c3..bc3cfee226f88 100644
--- a/source/Utility/PseudoTerminal.cpp
+++ b/source/Utility/PseudoTerminal.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+#include "lldb/Host/Config.h"
#include "lldb/Utility/PseudoTerminal.h"
#include <errno.h>
@@ -33,6 +34,7 @@ pid_t fork(void) { return 0; }
pid_t setsid(void) { return 0; }
#elif defined(__ANDROID_NDK__)
#include "lldb/Host/android/Android.h"
+int posix_openpt(int flags);
#endif
using namespace lldb_utility;
@@ -237,9 +239,11 @@ PseudoTerminal::Fork (char *error_str, size_t error_len)
{
if (error_str)
error_str[0] = '\0';
-
pid_t pid = LLDB_INVALID_PROCESS_ID;
- if (OpenFirstAvailableMaster (O_RDWR, error_str, error_len))
+#if !defined(LLDB_DISABLE_POSIX)
+ int flags = O_RDWR;
+ flags |= O_CLOEXEC;
+ if (OpenFirstAvailableMaster (flags, error_str, error_len))
{
// Successfully opened our master pseudo terminal
@@ -258,7 +262,8 @@ PseudoTerminal::Fork (char *error_str, size_t error_len)
if (OpenSlave (O_RDWR, error_str, error_len))
{
// Successfully opened slave
- // We are done with the master in the child process so lets close it
+
+ // Master FD should have O_CLOEXEC set, but let's close it just in case...
CloseMasterFileDescriptor ();
#if defined(TIOCSCTTY)
@@ -295,6 +300,7 @@ PseudoTerminal::Fork (char *error_str, size_t error_len)
// Do nothing and let the pid get returned!
}
}
+#endif
return pid;
}
diff --git a/source/Utility/StringExtractor.cpp b/source/Utility/StringExtractor.cpp
index a2cbe6cd48692..e82c83dfd0932 100644
--- a/source/Utility/StringExtractor.cpp
+++ b/source/Utility/StringExtractor.cpp
@@ -143,7 +143,7 @@ StringExtractor::GetU32 (uint32_t fail_value, int base)
char *end = nullptr;
const char *start = m_packet.c_str();
const char *cstr = start + m_index;
- uint32_t result = ::strtoul (cstr, &end, base);
+ uint32_t result = static_cast<uint32_t>(::strtoul (cstr, &end, base));
if (end && end != cstr)
{
@@ -162,7 +162,7 @@ StringExtractor::GetS32 (int32_t fail_value, int base)
char *end = nullptr;
const char *start = m_packet.c_str();
const char *cstr = start + m_index;
- int32_t result = ::strtol (cstr, &end, base);
+ int32_t result = static_cast<int32_t>(::strtol (cstr, &end, base));
if (end && end != cstr)
{
diff --git a/source/Utility/StringExtractorGDBRemote.cpp b/source/Utility/StringExtractorGDBRemote.cpp
index a137d365984f1..aeceaa00fa1c9 100644
--- a/source/Utility/StringExtractorGDBRemote.cpp
+++ b/source/Utility/StringExtractorGDBRemote.cpp
@@ -64,6 +64,10 @@ StringExtractorGDBRemote::GetServerPacketType () const
const char *packet_cstr = m_packet.c_str();
switch (m_packet[0])
{
+
+ case '%':
+ return eServerPacketType_notify;
+
case '\x03':
if (packet_size == 1) return eServerPacketType_interrupt;
break;
@@ -136,6 +140,14 @@ StringExtractorGDBRemote::GetServerPacketType () const
if (packet_size == 2) return eServerPacketType_qC;
break;
+ case 'E':
+ if (PACKET_STARTS_WITH ("qEcho:")) return eServerPacketType_qEcho;
+ break;
+
+ case 'F':
+ if (PACKET_STARTS_WITH ("qFileLoadAddress:")) return eServerPacketType_qFileLoadAddress;
+ break;
+
case 'G':
if (PACKET_STARTS_WITH ("qGroupName:")) return eServerPacketType_qGroupName;
if (PACKET_MATCHES ("qGetWorkingDir")) return eServerPacketType_qGetWorkingDir;
@@ -160,6 +172,7 @@ StringExtractorGDBRemote::GetServerPacketType () const
case 'M':
if (PACKET_STARTS_WITH ("qMemoryRegionInfo:")) return eServerPacketType_qMemoryRegionInfo;
if (PACKET_MATCHES ("qMemoryRegionInfo")) return eServerPacketType_qMemoryRegionInfoSupported;
+ if (PACKET_STARTS_WITH ("qModuleInfo:")) return eServerPacketType_qModuleInfo;
break;
case 'P':
diff --git a/source/Utility/StringExtractorGDBRemote.h b/source/Utility/StringExtractorGDBRemote.h
index b51be7d7c28a8..beb07e5b57ea4 100644
--- a/source/Utility/StringExtractorGDBRemote.h
+++ b/source/Utility/StringExtractorGDBRemote.h
@@ -50,15 +50,18 @@ public:
eServerPacketType_qfProcessInfo,
eServerPacketType_qsProcessInfo,
eServerPacketType_qC,
+ eServerPacketType_qEcho,
eServerPacketType_qGroupName,
eServerPacketType_qHostInfo,
eServerPacketType_qLaunchGDBServer,
eServerPacketType_qKillSpawnedProcess,
eServerPacketType_qLaunchSuccess,
+ eServerPacketType_qModuleInfo,
eServerPacketType_qProcessInfoPID,
eServerPacketType_qSpeedTest,
eServerPacketType_qUserName,
eServerPacketType_qGetWorkingDir,
+ eServerPacketType_qFileLoadAddress,
eServerPacketType_QEnvironment,
eServerPacketType_QLaunchArch,
eServerPacketType_QSetDisableASLR,
@@ -144,6 +147,7 @@ public:
eServerPacketType__M,
eServerPacketType__m,
+ eServerPacketType_notify, // '%' notification
};
ServerPacketType
diff --git a/source/Utility/UriParser.cpp b/source/Utility/UriParser.cpp
index 1d4402feec6e8..86020d17fc3e4 100644
--- a/source/Utility/UriParser.cpp
+++ b/source/Utility/UriParser.cpp
@@ -11,6 +11,7 @@
// C Includes
#include <stdlib.h>
+#include <stdio.h>
// C++ Includes
// Other libraries and framework includes