7
7
#include < cstdlib>
8
8
#include " sosplugin.h"
9
9
#include < string.h>
10
- #include < dbgtargetcontext.h>
11
10
#include < string>
12
11
13
12
ULONG g_currentThreadIndex = -1 ;
@@ -708,8 +707,8 @@ DebugClient::GetModuleDirectory(
708
707
// Internal function
709
708
ULONG64
710
709
DebugClient::GetModuleBase (
711
- lldb::SBTarget target,
712
- lldb::SBModule module )
710
+ /* const */ lldb::SBTarget& target,
711
+ /* const */ lldb::SBModule& module )
713
712
{
714
713
// Find the first section with an valid base address
715
714
int numSections = module .GetNumSections ();
@@ -922,6 +921,19 @@ DebugClient::GetThreadContextById(
922
921
dtcontext = (DT_CONTEXT*)context;
923
922
dtcontext->ContextFlags = contextFlags;
924
923
924
+ GetContextFromFrame (frame, dtcontext);
925
+ hr = S_OK;
926
+
927
+ exit:
928
+ return hr;
929
+ }
930
+
931
+ // Internal function
932
+ void
933
+ DebugClient::GetContextFromFrame (
934
+ /* const */ lldb::SBFrame& frame,
935
+ DT_CONTEXT *dtcontext)
936
+ {
925
937
#ifdef DBG_TARGET_AMD64
926
938
dtcontext->Rip = frame.GetPC ();
927
939
dtcontext->Rsp = frame.GetSP ();
@@ -969,29 +981,19 @@ DebugClient::GetThreadContextById(
969
981
dtcontext->R11 = GetRegister (frame, " r11" );
970
982
dtcontext->R12 = GetRegister (frame, " r12" );
971
983
#endif
972
-
973
- hr = S_OK;
974
-
975
- exit:
976
- return hr;
977
984
}
978
985
979
986
// Internal function
980
987
DWORD_PTR
981
- DebugClient::GetRegister (lldb::SBFrame frame, const char *name)
988
+ DebugClient::GetRegister (
989
+ /* const */ lldb::SBFrame& frame,
990
+ const char *name)
982
991
{
983
992
lldb::SBValue regValue = frame.FindRegister (name);
984
993
985
994
lldb::SBError error;
986
995
DWORD_PTR result = regValue.GetValueAsUnsigned (error);
987
996
988
- #ifdef _DEBUG
989
- if (!regValue.IsValid () || error.Fail ())
990
- {
991
- Output (DEBUG_OUTPUT_ERROR, " Invalid register name '%s'\n " , name);
992
- }
993
- #endif
994
-
995
997
return result;
996
998
}
997
999
@@ -1115,7 +1117,7 @@ DebugClient::GetExpression(
1115
1117
// Internal function
1116
1118
DWORD_PTR
1117
1119
DebugClient::GetExpression (
1118
- lldb::SBFrame frame,
1120
+ /* const */ lldb::SBFrame& frame,
1119
1121
lldb::SBError& error,
1120
1122
PCSTR exp)
1121
1123
{
@@ -1130,6 +1132,70 @@ DebugClient::GetExpression(
1130
1132
return result;
1131
1133
}
1132
1134
1135
+ HRESULT
1136
+ DebugClient::VirtualUnwind (
1137
+ DWORD threadID,
1138
+ ULONG32 contextSize,
1139
+ PBYTE context)
1140
+ {
1141
+ lldb::SBProcess process;
1142
+ lldb::SBThread thread;
1143
+
1144
+ if (context == NULL || contextSize < sizeof (DT_CONTEXT))
1145
+ {
1146
+ return E_FAIL;
1147
+ }
1148
+
1149
+ process = GetCurrentProcess ();
1150
+ if (!process.IsValid ())
1151
+ {
1152
+ return E_FAIL;
1153
+ }
1154
+
1155
+ thread = process.GetThreadByID (threadID);
1156
+ if (!thread.IsValid ())
1157
+ {
1158
+ return E_FAIL;
1159
+ }
1160
+
1161
+ DT_CONTEXT *dtcontext = (DT_CONTEXT*)context;
1162
+ lldb::SBFrame frameFound;
1163
+
1164
+ #ifdef DBG_TARGET_AMD64
1165
+ DWORD64 spToFind = dtcontext->Rsp ;
1166
+ #elif DBG_TARGET_ARM
1167
+ DWORD spToFind = dtcontext->Sp ;
1168
+ #endif
1169
+
1170
+ int numFrames = thread.GetNumFrames ();
1171
+ for (int i = 0 ; i < numFrames; i++)
1172
+ {
1173
+ lldb::SBFrame frame = thread.GetFrameAtIndex (i);
1174
+ if (!frame.IsValid ())
1175
+ {
1176
+ break ;
1177
+ }
1178
+
1179
+ lldb::addr_t sp = frame.GetSP ();
1180
+
1181
+ if (sp == spToFind && (i + 1 ) < numFrames)
1182
+ {
1183
+ // Get next frame after finding the match
1184
+ frameFound = thread.GetFrameAtIndex (i + 1 );
1185
+ break ;
1186
+ }
1187
+ }
1188
+
1189
+ if (!frameFound.IsValid ())
1190
+ {
1191
+ return E_FAIL;
1192
+ }
1193
+
1194
+ GetContextFromFrame (frameFound, dtcontext);
1195
+
1196
+ return S_OK;
1197
+ }
1198
+
1133
1199
// ----------------------------------------------------------------------------
1134
1200
// Helper functions
1135
1201
// ----------------------------------------------------------------------------
0 commit comments