[Lldb-commits] [lldb] r352507 - BreakpadRecords: Add parsing code for FILE and LINE records
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Jan 29 07:39:27 PST 2019
Author: labath
Date: Tue Jan 29 07:39:27 2019
New Revision: 352507
URL: http://llvm.org/viewvc/llvm-project?rev=352507&view=rev
Log:
BreakpadRecords: Add parsing code for FILE and LINE records
The two records aren't used by anything yet, but this part can be
separated out easily, so I am comitting it separately to simplify
reviews of the followup patch.
Modified:
lldb/trunk/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp
lldb/trunk/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.h
lldb/trunk/unittests/ObjectFile/Breakpad/BreakpadRecordsTest.cpp
Modified: lldb/trunk/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp?rev=352507&r1=352506&r2=352507&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp Tue Jan 29 07:39:27 2019
@@ -198,6 +198,30 @@ llvm::raw_ostream &breakpad::operator<<(
return OS << "INFO CODE_ID " << R.ID.GetAsString();
}
+llvm::Optional<FileRecord> FileRecord::parse(llvm::StringRef Line) {
+ // FILE number name
+ llvm::StringRef Str;
+ std::tie(Str, Line) = getToken(Line);
+ if (toToken(Str) != Token::File)
+ return llvm::None;
+
+ size_t Number;
+ std::tie(Str, Line) = getToken(Line);
+ if (!to_integer(Str, Number))
+ return llvm::None;
+
+ llvm::StringRef Name = Line.trim();
+ if (Name.empty())
+ return llvm::None;
+
+ return FileRecord(Number, Name);
+}
+
+llvm::raw_ostream &breakpad::operator<<(llvm::raw_ostream &OS,
+ const FileRecord &R) {
+ return OS << "FILE " << R.Number << " " << R.Name;
+}
+
static bool parsePublicOrFunc(llvm::StringRef Line, bool &Multiple,
lldb::addr_t &Address, lldb::addr_t *Size,
lldb::addr_t &ParamSize, llvm::StringRef &Name) {
@@ -259,6 +283,41 @@ llvm::raw_ostream &breakpad::operator<<(
R.ParamSize, R.Name);
}
+llvm::Optional<LineRecord> LineRecord::parse(llvm::StringRef Line) {
+ lldb::addr_t Address;
+ llvm::StringRef Str;
+ std::tie(Str, Line) = getToken(Line);
+ if (!to_integer(Str, Address, 16))
+ return llvm::None;
+
+ lldb::addr_t Size;
+ std::tie(Str, Line) = getToken(Line);
+ if (!to_integer(Str, Size, 16))
+ return llvm::None;
+
+ uint32_t LineNum;
+ std::tie(Str, Line) = getToken(Line);
+ if (!to_integer(Str, LineNum))
+ return llvm::None;
+
+ size_t FileNum;
+ std::tie(Str, Line) = getToken(Line);
+ if (!to_integer(Str, FileNum))
+ return llvm::None;
+
+ return LineRecord(Address, Size, LineNum, FileNum);
+}
+
+bool breakpad::operator==(const LineRecord &L, const LineRecord &R) {
+ return L.Address == R.Address && L.Size == R.Size && L.LineNum == R.LineNum &&
+ L.FileNum == R.FileNum;
+}
+llvm::raw_ostream &breakpad::operator<<(llvm::raw_ostream &OS,
+ const LineRecord &R) {
+ return OS << llvm::formatv("{0:x-} {1:x-} {2} {3}", R.Address, R.Size,
+ R.LineNum, R.FileNum);
+}
+
llvm::Optional<PublicRecord> PublicRecord::parse(llvm::StringRef Line) {
bool Multiple;
lldb::addr_t Address, ParamSize;
Modified: lldb/trunk/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.h?rev=352507&r1=352506&r2=352507&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.h (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.h Tue Jan 29 07:39:27 2019
@@ -74,6 +74,21 @@ inline bool operator==(const InfoRecord
}
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const InfoRecord &R);
+class FileRecord : public Record {
+public:
+ static llvm::Optional<FileRecord> parse(llvm::StringRef Line);
+ FileRecord(size_t Number, llvm::StringRef Name)
+ : Record(File), Number(Number), Name(Name) {}
+
+ size_t Number;
+ llvm::StringRef Name;
+};
+
+inline bool operator==(const FileRecord &L, const FileRecord &R) {
+ return L.Number == R.Number && L.Name == R.Name;
+}
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const FileRecord &R);
+
class FuncRecord : public Record {
public:
static llvm::Optional<FuncRecord> parse(llvm::StringRef Line);
@@ -92,6 +107,23 @@ public:
bool operator==(const FuncRecord &L, const FuncRecord &R);
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const FuncRecord &R);
+class LineRecord : public Record {
+public:
+ static llvm::Optional<LineRecord> parse(llvm::StringRef Line);
+ LineRecord(lldb::addr_t Address, lldb::addr_t Size, uint32_t LineNum,
+ size_t FileNum)
+ : Record(Line), Address(Address), Size(Size), LineNum(LineNum),
+ FileNum(FileNum) {}
+
+ lldb::addr_t Address;
+ lldb::addr_t Size;
+ uint32_t LineNum;
+ size_t FileNum;
+};
+
+bool operator==(const LineRecord &L, const LineRecord &R);
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const LineRecord &R);
+
class PublicRecord : public Record {
public:
static llvm::Optional<PublicRecord> parse(llvm::StringRef Line);
Modified: lldb/trunk/unittests/ObjectFile/Breakpad/BreakpadRecordsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/ObjectFile/Breakpad/BreakpadRecordsTest.cpp?rev=352507&r1=352506&r2=352507&view=diff
==============================================================================
--- lldb/trunk/unittests/ObjectFile/Breakpad/BreakpadRecordsTest.cpp (original)
+++ lldb/trunk/unittests/ObjectFile/Breakpad/BreakpadRecordsTest.cpp Tue Jan 29 07:39:27 2019
@@ -50,6 +50,13 @@ TEST(InfoRecord, parse) {
EXPECT_EQ(llvm::None, InfoRecord::parse("INFO CODE_ID"));
}
+TEST(FileRecord, parse) {
+ EXPECT_EQ(FileRecord(47, "foo"), FileRecord::parse("FILE 47 foo"));
+ EXPECT_EQ(llvm::None, FileRecord::parse("FILE 47"));
+ EXPECT_EQ(llvm::None, FileRecord::parse("FILE"));
+ EXPECT_EQ(llvm::None, FileRecord::parse(""));
+}
+
TEST(FuncRecord, parse) {
EXPECT_EQ(FuncRecord(true, 0x47, 0x7, 0x8, "foo"),
FuncRecord::parse("FUNC m 47 7 8 foo"));
@@ -64,6 +71,15 @@ TEST(FuncRecord, parse) {
EXPECT_EQ(llvm::None, FuncRecord::parse("FUNC"));
}
+TEST(LineRecord, parse) {
+ EXPECT_EQ(LineRecord(0x47, 0x74, 47, 74), LineRecord::parse("47 74 47 74"));
+ EXPECT_EQ(llvm::None, LineRecord::parse("47 74 47"));
+ EXPECT_EQ(llvm::None, LineRecord::parse("47 74"));
+ EXPECT_EQ(llvm::None, LineRecord::parse("47"));
+ EXPECT_EQ(llvm::None, LineRecord::parse(""));
+ EXPECT_EQ(llvm::None, LineRecord::parse("FUNC"));
+}
+
TEST(PublicRecord, parse) {
EXPECT_EQ(PublicRecord(true, 0x47, 0x8, "foo"),
PublicRecord::parse("PUBLIC m 47 8 foo"));
More information about the lldb-commits
mailing list