Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 738c0f0

Browse files
author
Greg Clayton
committedNov 13, 2013
<rdar://problem/15172417>
Added two new GDB server packets to debugserver: "QSaveRegisterState" and "QRestoreRegiterState". "QSaveRegisterState" makes the remote GDB server save all register values and it returns a save identifier as an unsigned integer. This packet can be used prior to running expressions to save all registers. All registers can them we later restored with "QRestoreRegiterState:SAVEID" what SAVEID is the integer identifier that was returned from the call to QSaveRegisterState. Cleaned up redundant code in lldb_private::Thread, lldb_private::ThreadPlanCallFunction. Moved the lldb_private::Thread::RegisterCheckpoint into its own header file and it is now in the lldb_private namespace. Trimmed down the RegisterCheckpoint class to omit stuff that wasn't used (the stack ID). Added a few new virtual methods to lldb_private::RegisterContext that allow subclasses to efficiently save/restore register states and changed the RegisterContextGDBRemote to take advantage of these new calls. git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@194621 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 103ed0a commit 738c0f0

28 files changed

+822
-311
lines changed
 
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//===-- RegisterCheckpoint.h ------------------------------------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef liblldb_RegisterCheckpoint_h_
11+
#define liblldb_RegisterCheckpoint_h_
12+
13+
#include "lldb/lldb-private.h"
14+
#include "lldb/Core/UserID.h"
15+
#include "lldb/Target/StackID.h"
16+
17+
namespace lldb_private {
18+
19+
// Inherit from UserID in case pushing/popping all register values can be
20+
// done using a 64 bit integer that holds a baton/cookie instead of actually
21+
// having to read all register values into a buffer
22+
class RegisterCheckpoint : public UserID
23+
{
24+
public:
25+
26+
enum class Reason {
27+
// An expression is about to be run on the thread if the protocol that
28+
// talks to the debuggee supports checkpointing the registers using a
29+
// push/pop then the UserID base class in the RegisterCheckpoint can
30+
// be used to store the baton/cookie that refers to the remote saved
31+
// state.
32+
eExpression,
33+
// The register checkpoint wants the raw register bytes, so they must
34+
// be read into m_data_sp, or the save/restore checkpoint should fail.
35+
eDataBackup
36+
};
37+
38+
RegisterCheckpoint(Reason reason) :
39+
UserID(0),
40+
m_data_sp (),
41+
m_reason(reason)
42+
{
43+
}
44+
45+
~RegisterCheckpoint()
46+
{
47+
}
48+
49+
lldb::DataBufferSP &
50+
GetData()
51+
{
52+
return m_data_sp;
53+
}
54+
55+
const lldb::DataBufferSP &
56+
GetData() const
57+
{
58+
return m_data_sp;
59+
}
60+
61+
protected:
62+
lldb::DataBufferSP m_data_sp;
63+
Reason m_reason;
64+
65+
// Make RegisterCheckpointSP if you wish to share the data in this class.
66+
DISALLOW_COPY_AND_ASSIGN(RegisterCheckpoint);
67+
};
68+
69+
} // namespace lldb_private
70+
71+
#endif // liblldb_RegisterCheckpoint_h_

‎include/lldb/Target/RegisterContext.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ class RegisterContext :
5959
virtual bool
6060
WriteRegister (const RegisterInfo *reg_info, const RegisterValue &reg_value) = 0;
6161

62+
virtual bool
63+
ReadAllRegisterValues (lldb::DataBufferSP &data_sp)
64+
{
65+
return false;
66+
}
67+
68+
virtual bool
69+
WriteAllRegisterValues (const lldb::DataBufferSP &data_sp)
70+
{
71+
return false;
72+
}
73+
6274
// These two functions are used to implement "push" and "pop" of register states. They are used primarily
6375
// for expression evaluation, where we need to push a new state (storing the old one in data_sp) and then
6476
// restoring the original state by passing the data_sp we got from ReadAllRegisters to WriteAllRegisterValues.
@@ -67,10 +79,10 @@ class RegisterContext :
6779
// so these API's should only be used when this behavior is needed.
6880

6981
virtual bool
70-
ReadAllRegisterValues (lldb::DataBufferSP &data_sp) = 0;
71-
82+
ReadAllRegisterValues (lldb_private::RegisterCheckpoint &reg_checkpoint);
83+
7284
virtual bool
73-
WriteAllRegisterValues (const lldb::DataBufferSP &data_sp) = 0;
85+
WriteAllRegisterValues (const lldb_private::RegisterCheckpoint &reg_checkpoint);
7486

7587
bool
7688
CopyFromRegisterContext (lldb::RegisterContextSP context);

‎include/lldb/Target/Thread.h

Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "lldb/Core/UserID.h"
1818
#include "lldb/Core/UserSettingsController.h"
1919
#include "lldb/Target/ExecutionContextScope.h"
20+
#include "lldb/Target/RegisterCheckpoint.h"
2021
#include "lldb/Target/StackFrameList.h"
2122

2223
#define LLDB_THREAD_MAX_STOP_EXC_DATA 8
@@ -130,79 +131,12 @@ class Thread :
130131
DISALLOW_COPY_AND_ASSIGN (ThreadEventData);
131132
};
132133

133-
// TODO: You shouldn't just checkpoint the register state alone, so this should get
134-
// moved to protected. To do that ThreadStateCheckpoint needs to be returned as a token...
135-
class RegisterCheckpoint
136-
{
137-
public:
138-
139-
RegisterCheckpoint() :
140-
m_stack_id (),
141-
m_data_sp ()
142-
{
143-
}
144-
145-
RegisterCheckpoint (const StackID &stack_id) :
146-
m_stack_id (stack_id),
147-
m_data_sp ()
148-
{
149-
}
150-
151-
~RegisterCheckpoint()
152-
{
153-
}
154-
155-
const RegisterCheckpoint&
156-
operator= (const RegisterCheckpoint &rhs)
157-
{
158-
if (this != &rhs)
159-
{
160-
this->m_stack_id = rhs.m_stack_id;
161-
this->m_data_sp = rhs.m_data_sp;
162-
}
163-
return *this;
164-
}
165-
166-
RegisterCheckpoint (const RegisterCheckpoint &rhs) :
167-
m_stack_id (rhs.m_stack_id),
168-
m_data_sp (rhs.m_data_sp)
169-
{
170-
}
171-
172-
const StackID &
173-
GetStackID()
174-
{
175-
return m_stack_id;
176-
}
177-
178-
void
179-
SetStackID (const StackID &stack_id)
180-
{
181-
m_stack_id = stack_id;
182-
}
183-
184-
lldb::DataBufferSP &
185-
GetData()
186-
{
187-
return m_data_sp;
188-
}
189-
190-
const lldb::DataBufferSP &
191-
GetData() const
192-
{
193-
return m_data_sp;
194-
}
195-
196-
protected:
197-
StackID m_stack_id;
198-
lldb::DataBufferSP m_data_sp;
199-
};
200134

201135
struct ThreadStateCheckpoint
202136
{
203137
uint32_t orig_stop_id; // Dunno if I need this yet but it is an interesting bit of data.
204138
lldb::StopInfoSP stop_info_sp; // You have to restore the stop info or you might continue with the wrong signals.
205-
RegisterCheckpoint register_backup; // You need to restore the registers, of course...
139+
lldb::RegisterCheckpointSP register_backup_sp; // You need to restore the registers, of course...
206140
uint32_t current_inlined_depth;
207141
lldb::addr_t current_inlined_pc;
208142
};
@@ -1004,16 +938,6 @@ class Thread :
1004938

1005939
typedef std::vector<lldb::ThreadPlanSP> plan_stack;
1006940

1007-
virtual bool
1008-
SaveFrameZeroState (RegisterCheckpoint &checkpoint);
1009-
1010-
virtual bool
1011-
RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint);
1012-
1013-
// register_data_sp must be a DataSP passed to ReadAllRegisterValues.
1014-
bool
1015-
ResetFrameZeroRegisters (lldb::DataBufferSP register_data_sp);
1016-
1017941
virtual lldb_private::Unwind *
1018942
GetUnwinder ();
1019943

@@ -1035,12 +959,6 @@ class Thread :
1035959
lldb::StackFrameListSP
1036960
GetStackFrameList ();
1037961

1038-
struct ThreadState
1039-
{
1040-
uint32_t orig_stop_id;
1041-
lldb::StopInfoSP stop_info_sp;
1042-
RegisterCheckpoint register_backup;
1043-
};
1044962

1045963
//------------------------------------------------------------------
1046964
// Classes that inherit from Process can see and modify these

‎include/lldb/Target/ThreadPlanCallFunction.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ class ThreadPlanCallFunction : public ThreadPlan
163163
Address m_function_addr;
164164
Address m_start_addr;
165165
lldb::addr_t m_function_sp;
166-
Thread::RegisterCheckpoint m_register_backup;
167166
lldb::ThreadPlanSP m_subplan_sp;
168167
LanguageRuntime *m_cxx_language_runtime;
169168
LanguageRuntime *m_objc_language_runtime;

‎include/lldb/lldb-forward.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class PythonDictionary;
162162
class PythonInteger;
163163
class PythonObject;
164164
class PythonString;
165+
class RegisterCheckpoint;
165166
class RegisterContext;
166167
class RegisterLocation;
167168
class RegisterLocationList;
@@ -329,6 +330,7 @@ namespace lldb {
329330
typedef std::shared_ptr<lldb_private::ProcessLaunchInfo> ProcessLaunchInfoSP;
330331
typedef std::weak_ptr<lldb_private::Process> ProcessWP;
331332
typedef std::shared_ptr<lldb_private::Property> PropertySP;
333+
typedef std::shared_ptr<lldb_private::RegisterCheckpoint> RegisterCheckpointSP;
332334
typedef std::shared_ptr<lldb_private::RegisterContext> RegisterContextSP;
333335
typedef std::shared_ptr<lldb_private::RegularExpression> RegularExpressionSP;
334336
typedef std::shared_ptr<lldb_private::ScriptInterpreterObject> ScriptInterpreterObjectSP;

‎lldb.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@
427427
26A527C414E24F5F00F3A14A /* ThreadMachCore.h in Headers */ = {isa = PBXBuildFile; fileRef = 26A527C014E24F5F00F3A14A /* ThreadMachCore.h */; };
428428
26A69C5F137A17A500262477 /* RegisterValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26C6886E137880C400407EDF /* RegisterValue.cpp */; };
429429
26A7A035135E6E4200FB369E /* OptionValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26A7A034135E6E4200FB369E /* OptionValue.cpp */; };
430+
26AB54121832DC3400EADFF3 /* RegisterCheckpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 26AB54111832DC3400EADFF3 /* RegisterCheckpoint.h */; };
430431
26AB92121819D74600E63F3E /* DWARFDataExtractor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26AB92101819D74600E63F3E /* DWARFDataExtractor.cpp */; };
431432
26AB92131819D74600E63F3E /* DWARFDataExtractor.h in Headers */ = {isa = PBXBuildFile; fileRef = 26AB92111819D74600E63F3E /* DWARFDataExtractor.h */; };
432433
26ACEC2815E077AE00E94760 /* Property.h in Headers */ = {isa = PBXBuildFile; fileRef = 26ACEC2715E077AE00E94760 /* Property.h */; };
@@ -1090,6 +1091,7 @@
10901091
26A527C014E24F5F00F3A14A /* ThreadMachCore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadMachCore.h; sourceTree = "<group>"; };
10911092
26A7A034135E6E4200FB369E /* OptionValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = OptionValue.cpp; path = source/Interpreter/OptionValue.cpp; sourceTree = "<group>"; };
10921093
26A7A036135E6E5300FB369E /* OptionValue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = OptionValue.h; path = include/lldb/Interpreter/OptionValue.h; sourceTree = "<group>"; };
1094+
26AB54111832DC3400EADFF3 /* RegisterCheckpoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RegisterCheckpoint.h; path = include/lldb/Target/RegisterCheckpoint.h; sourceTree = "<group>"; };
10931095
26AB92101819D74600E63F3E /* DWARFDataExtractor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DWARFDataExtractor.cpp; sourceTree = "<group>"; };
10941096
26AB92111819D74600E63F3E /* DWARFDataExtractor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DWARFDataExtractor.h; sourceTree = "<group>"; };
10951097
26ACEC2715E077AE00E94760 /* Property.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Property.h; path = include/lldb/Interpreter/Property.h; sourceTree = "<group>"; };
@@ -3118,6 +3120,7 @@
31183120
264A43BD1320BCEB005B4096 /* Platform.cpp */,
31193121
26BC7DF310F1B81A00F91463 /* Process.h */,
31203122
26BC7F3610F1B90C00F91463 /* Process.cpp */,
3123+
26AB54111832DC3400EADFF3 /* RegisterCheckpoint.h */,
31213124
26BC7DF410F1B81A00F91463 /* RegisterContext.h */,
31223125
26BC7F3710F1B90C00F91463 /* RegisterContext.cpp */,
31233126
2618D78F1240115500F2B8FE /* SectionLoadList.h */,
@@ -3611,6 +3614,7 @@
36113614
AF254E32170CCC33007AE5C9 /* PlatformDarwinKernel.h in Headers */,
36123615
2694E99E14FC0BB30076DE67 /* PlatformFreeBSD.h in Headers */,
36133616
2694E9A514FC0BBD0076DE67 /* PlatformLinux.h in Headers */,
3617+
26AB54121832DC3400EADFF3 /* RegisterCheckpoint.h in Headers */,
36143618
26AB92131819D74600E63F3E /* DWARFDataExtractor.h in Headers */,
36153619
2663E379152BD1890091EC22 /* ReadWriteLock.h in Headers */,
36163620
945759681534941F005A9070 /* PlatformPOSIX.h in Headers */,

0 commit comments

Comments
 (0)
This repository has been archived.