[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- UUID.cpp ----------------------------------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-03-04 09:28:55 +08:00
|
|
|
#include "lldb/Utility/UUID.h"
|
|
|
|
|
2017-03-04 09:30:05 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
UUID: Add support for arbitrary-sized module IDs
Summary:
The data structure is optimized for the case where the UUID size is <=
20 bytes (standard length emitted by the GNU linkers), but larger sizes
are also possible.
I've modified the string conversion function to support the new sizes as
well. For standard UUIDs it maintains the traditional formatting
(4-2-2-2-6). If a UUID is shorter, we just cut this sequence short, and
for longer UUIDs it will just repeat the last 6-byte block as long as
necessary.
I've also modified ObjectFileELF to take advantage of the new UUIDs and
avoid manually padding the UUID to 16 bytes. While there, I also made
sure the computed UUID does not depend on host endianness.
Reviewers: clayborg, lemo, sas, davide, espindola
Subscribers: emaste, arichardson, lldb-commits
Differential Revision: https://reviews.llvm.org/D48633
llvm-svn: 335963
2018-06-29 19:20:29 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2017-03-04 09:30:05 +08:00
|
|
|
|
2021-05-26 18:19:37 +08:00
|
|
|
#include <cctype>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
2010-06-10 03:36:54 +08:00
|
|
|
|
2018-06-21 23:24:39 +08:00
|
|
|
using namespace lldb_private;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
UUID: Add support for arbitrary-sized module IDs
Summary:
The data structure is optimized for the case where the UUID size is <=
20 bytes (standard length emitted by the GNU linkers), but larger sizes
are also possible.
I've modified the string conversion function to support the new sizes as
well. For standard UUIDs it maintains the traditional formatting
(4-2-2-2-6). If a UUID is shorter, we just cut this sequence short, and
for longer UUIDs it will just repeat the last 6-byte block as long as
necessary.
I've also modified ObjectFileELF to take advantage of the new UUIDs and
avoid manually padding the UUID to 16 bytes. While there, I also made
sure the computed UUID does not depend on host endianness.
Reviewers: clayborg, lemo, sas, davide, espindola
Subscribers: emaste, arichardson, lldb-commits
Differential Revision: https://reviews.llvm.org/D48633
llvm-svn: 335963
2018-06-29 19:20:29 +08:00
|
|
|
// Whether to put a separator after count uuid bytes.
|
|
|
|
// For the first 16 bytes we follow the traditional UUID format. After that, we
|
|
|
|
// simply put a dash after every 6 bytes.
|
|
|
|
static inline bool separate(size_t count) {
|
|
|
|
if (count >= 10)
|
|
|
|
return (count - 10) % 6 == 0;
|
|
|
|
|
|
|
|
switch (count) {
|
|
|
|
case 4:
|
|
|
|
case 6:
|
|
|
|
case 8:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2020-10-29 02:23:56 +08:00
|
|
|
UUID UUID::fromCvRecord(UUID::CvRecordPdb70 debug_info) {
|
|
|
|
llvm::sys::swapByteOrder(debug_info.Uuid.Data1);
|
|
|
|
llvm::sys::swapByteOrder(debug_info.Uuid.Data2);
|
|
|
|
llvm::sys::swapByteOrder(debug_info.Uuid.Data3);
|
|
|
|
llvm::sys::swapByteOrder(debug_info.Age);
|
|
|
|
if (debug_info.Age)
|
|
|
|
return UUID::fromOptionalData(&debug_info, sizeof(debug_info));
|
|
|
|
return UUID::fromOptionalData(&debug_info.Uuid, sizeof(debug_info.Uuid));
|
|
|
|
}
|
|
|
|
|
UUID: Add support for arbitrary-sized module IDs
Summary:
The data structure is optimized for the case where the UUID size is <=
20 bytes (standard length emitted by the GNU linkers), but larger sizes
are also possible.
I've modified the string conversion function to support the new sizes as
well. For standard UUIDs it maintains the traditional formatting
(4-2-2-2-6). If a UUID is shorter, we just cut this sequence short, and
for longer UUIDs it will just repeat the last 6-byte block as long as
necessary.
I've also modified ObjectFileELF to take advantage of the new UUIDs and
avoid manually padding the UUID to 16 bytes. While there, I also made
sure the computed UUID does not depend on host endianness.
Reviewers: clayborg, lemo, sas, davide, espindola
Subscribers: emaste, arichardson, lldb-commits
Differential Revision: https://reviews.llvm.org/D48633
llvm-svn: 335963
2018-06-29 19:20:29 +08:00
|
|
|
std::string UUID::GetAsString(llvm::StringRef separator) const {
|
2013-05-04 07:56:12 +08:00
|
|
|
std::string result;
|
UUID: Add support for arbitrary-sized module IDs
Summary:
The data structure is optimized for the case where the UUID size is <=
20 bytes (standard length emitted by the GNU linkers), but larger sizes
are also possible.
I've modified the string conversion function to support the new sizes as
well. For standard UUIDs it maintains the traditional formatting
(4-2-2-2-6). If a UUID is shorter, we just cut this sequence short, and
for longer UUIDs it will just repeat the last 6-byte block as long as
necessary.
I've also modified ObjectFileELF to take advantage of the new UUIDs and
avoid manually padding the UUID to 16 bytes. While there, I also made
sure the computed UUID does not depend on host endianness.
Reviewers: clayborg, lemo, sas, davide, espindola
Subscribers: emaste, arichardson, lldb-commits
Differential Revision: https://reviews.llvm.org/D48633
llvm-svn: 335963
2018-06-29 19:20:29 +08:00
|
|
|
llvm::raw_string_ostream os(result);
|
|
|
|
|
|
|
|
for (auto B : llvm::enumerate(GetBytes())) {
|
|
|
|
if (separate(B.index()))
|
|
|
|
os << separator;
|
|
|
|
|
|
|
|
os << llvm::format_hex_no_prefix(B.value(), 2, true);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
UUID: Add support for arbitrary-sized module IDs
Summary:
The data structure is optimized for the case where the UUID size is <=
20 bytes (standard length emitted by the GNU linkers), but larger sizes
are also possible.
I've modified the string conversion function to support the new sizes as
well. For standard UUIDs it maintains the traditional formatting
(4-2-2-2-6). If a UUID is shorter, we just cut this sequence short, and
for longer UUIDs it will just repeat the last 6-byte block as long as
necessary.
I've also modified ObjectFileELF to take advantage of the new UUIDs and
avoid manually padding the UUID to 16 bytes. While there, I also made
sure the computed UUID does not depend on host endianness.
Reviewers: clayborg, lemo, sas, davide, espindola
Subscribers: emaste, arichardson, lldb-commits
Differential Revision: https://reviews.llvm.org/D48633
llvm-svn: 335963
2018-06-29 19:20:29 +08:00
|
|
|
os.flush();
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return result;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-12-13 08:15:17 +08:00
|
|
|
void UUID::Dump(Stream *s) const { s->PutCString(GetAsString()); }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
static inline int xdigit_to_int(char ch) {
|
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
|
|
|
ch = tolower(ch);
|
|
|
|
if (ch >= 'a' && ch <= 'f')
|
|
|
|
return 10 + ch - 'a';
|
2010-06-09 00:52:24 +08:00
|
|
|
return ch - '0';
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
UUID: Add support for arbitrary-sized module IDs
Summary:
The data structure is optimized for the case where the UUID size is <=
20 bytes (standard length emitted by the GNU linkers), but larger sizes
are also possible.
I've modified the string conversion function to support the new sizes as
well. For standard UUIDs it maintains the traditional formatting
(4-2-2-2-6). If a UUID is shorter, we just cut this sequence short, and
for longer UUIDs it will just repeat the last 6-byte block as long as
necessary.
I've also modified ObjectFileELF to take advantage of the new UUIDs and
avoid manually padding the UUID to 16 bytes. While there, I also made
sure the computed UUID does not depend on host endianness.
Reviewers: clayborg, lemo, sas, davide, espindola
Subscribers: emaste, arichardson, lldb-commits
Differential Revision: https://reviews.llvm.org/D48633
llvm-svn: 335963
2018-06-29 19:20:29 +08:00
|
|
|
llvm::StringRef
|
|
|
|
UUID::DecodeUUIDBytesFromString(llvm::StringRef p,
|
2020-06-02 04:43:18 +08:00
|
|
|
llvm::SmallVectorImpl<uint8_t> &uuid_bytes) {
|
UUID: Add support for arbitrary-sized module IDs
Summary:
The data structure is optimized for the case where the UUID size is <=
20 bytes (standard length emitted by the GNU linkers), but larger sizes
are also possible.
I've modified the string conversion function to support the new sizes as
well. For standard UUIDs it maintains the traditional formatting
(4-2-2-2-6). If a UUID is shorter, we just cut this sequence short, and
for longer UUIDs it will just repeat the last 6-byte block as long as
necessary.
I've also modified ObjectFileELF to take advantage of the new UUIDs and
avoid manually padding the UUID to 16 bytes. While there, I also made
sure the computed UUID does not depend on host endianness.
Reviewers: clayborg, lemo, sas, davide, espindola
Subscribers: emaste, arichardson, lldb-commits
Differential Revision: https://reviews.llvm.org/D48633
llvm-svn: 335963
2018-06-29 19:20:29 +08:00
|
|
|
uuid_bytes.clear();
|
2020-06-02 04:43:18 +08:00
|
|
|
while (p.size() >= 2) {
|
2016-11-17 09:37:42 +08:00
|
|
|
if (isxdigit(p[0]) && isxdigit(p[1])) {
|
|
|
|
int hi_nibble = xdigit_to_int(p[0]);
|
|
|
|
int lo_nibble = xdigit_to_int(p[1]);
|
|
|
|
// Translate the two hex nibble characters into a byte
|
UUID: Add support for arbitrary-sized module IDs
Summary:
The data structure is optimized for the case where the UUID size is <=
20 bytes (standard length emitted by the GNU linkers), but larger sizes
are also possible.
I've modified the string conversion function to support the new sizes as
well. For standard UUIDs it maintains the traditional formatting
(4-2-2-2-6). If a UUID is shorter, we just cut this sequence short, and
for longer UUIDs it will just repeat the last 6-byte block as long as
necessary.
I've also modified ObjectFileELF to take advantage of the new UUIDs and
avoid manually padding the UUID to 16 bytes. While there, I also made
sure the computed UUID does not depend on host endianness.
Reviewers: clayborg, lemo, sas, davide, espindola
Subscribers: emaste, arichardson, lldb-commits
Differential Revision: https://reviews.llvm.org/D48633
llvm-svn: 335963
2018-06-29 19:20:29 +08:00
|
|
|
uuid_bytes.push_back((hi_nibble << 4) + lo_nibble);
|
2016-11-17 09:37:42 +08:00
|
|
|
|
|
|
|
// Skip both hex digits
|
|
|
|
p = p.drop_front(2);
|
|
|
|
} else if (p.front() == '-') {
|
|
|
|
// Skip dashes
|
|
|
|
p = p.drop_front();
|
|
|
|
} else {
|
|
|
|
// UUID values can only consist of hex characters and '-' chars
|
|
|
|
break;
|
2013-05-24 04:57:03 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-11-17 09:37:42 +08:00
|
|
|
return p;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2020-06-02 04:43:18 +08:00
|
|
|
bool UUID::SetFromStringRef(llvm::StringRef str) {
|
2017-05-12 13:49:54 +08:00
|
|
|
llvm::StringRef p = str;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Skip leading whitespace characters
|
2016-11-17 09:37:42 +08:00
|
|
|
p = p.ltrim();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
UUID: Add support for arbitrary-sized module IDs
Summary:
The data structure is optimized for the case where the UUID size is <=
20 bytes (standard length emitted by the GNU linkers), but larger sizes
are also possible.
I've modified the string conversion function to support the new sizes as
well. For standard UUIDs it maintains the traditional formatting
(4-2-2-2-6). If a UUID is shorter, we just cut this sequence short, and
for longer UUIDs it will just repeat the last 6-byte block as long as
necessary.
I've also modified ObjectFileELF to take advantage of the new UUIDs and
avoid manually padding the UUID to 16 bytes. While there, I also made
sure the computed UUID does not depend on host endianness.
Reviewers: clayborg, lemo, sas, davide, espindola
Subscribers: emaste, arichardson, lldb-commits
Differential Revision: https://reviews.llvm.org/D48633
llvm-svn: 335963
2018-06-29 19:20:29 +08:00
|
|
|
llvm::SmallVector<uint8_t, 20> bytes;
|
2020-06-02 04:43:18 +08:00
|
|
|
llvm::StringRef rest = UUID::DecodeUUIDBytesFromString(p, bytes);
|
|
|
|
|
|
|
|
// Return false if we could not consume the entire string or if the parsed
|
|
|
|
// UUID is empty.
|
|
|
|
if (!rest.empty() || bytes.empty())
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2020-06-02 04:43:18 +08:00
|
|
|
*this = fromData(bytes);
|
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2019-01-25 06:43:44 +08:00
|
|
|
|
2020-06-02 04:43:18 +08:00
|
|
|
bool UUID::SetFromOptionalStringRef(llvm::StringRef str) {
|
|
|
|
bool result = SetFromStringRef(str);
|
|
|
|
if (result) {
|
2019-01-25 06:43:44 +08:00
|
|
|
if (llvm::all_of(m_bytes, [](uint8_t b) { return b == 0; }))
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
2020-06-02 04:43:18 +08:00
|
|
|
return result;
|
|
|
|
}
|