12
12
#include " lldb/Core/ConstString.h"
13
13
#include " lldb/Core/DataExtractor.h"
14
14
#include " lldb/Core/Error.h"
15
+ #include " lldb/Core/Log.h"
15
16
#include " lldb/Core/Module.h"
16
17
#include " lldb/Core/PluginManager.h"
17
18
#include " lldb/Core/Value.h"
@@ -60,6 +61,17 @@ ABISysV_x86_64::PrepareTrivialCall (Thread &thread,
60
61
lldb::addr_t arg,
61
62
lldb::addr_t *this_arg) const
62
63
{
64
+ Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
65
+
66
+ if (log)
67
+ log->Printf (" ABISysV_x86_64::PrepareTrivialCall\n (\n thread = %p\n sp = 0x%llx\n functionAddress = 0x%llx\n returnAddress = 0x%llx\n arg = 0x%llx\n this_arg = %p(0x%llx)\n )" ,
68
+ (void *)&thread,
69
+ (uint64_t )sp,
70
+ (uint64_t )functionAddress,
71
+ (uint64_t )returnAddress,
72
+ (void *)arg,
73
+ this_arg ? (uint64_t )*this_arg : (uint64_t )0 );
74
+
63
75
RegisterContext *reg_ctx = thread.GetRegisterContext ();
64
76
if (!reg_ctx)
65
77
return false ;
@@ -78,21 +90,39 @@ ABISysV_x86_64::PrepareTrivialCall (Thread &thread,
78
90
79
91
if (this_arg)
80
92
{
93
+ if (log)
94
+ log->PutCString (" The trivial call has a this pointer" );
95
+
81
96
uint32_t rsiID = reg_ctx->GetRegisterInfoByName (" rsi" , 0 )->kinds [eRegisterKindLLDB];
82
97
98
+ if (log)
99
+ log->Printf (" About to write 'this' (0x%llx) into RDI" , (uint64_t )*this_arg);
100
+
83
101
if (!reg_ctx->WriteRegisterFromUnsigned (rdiID, *this_arg))
84
102
return false ;
85
103
104
+ if (log)
105
+ log->Printf (" About to write the argument (0x%llx) into RSI" , (uint64_t )arg);
106
+
86
107
if (!reg_ctx->WriteRegisterFromUnsigned (rsiID, arg))
87
108
return false ;
88
109
}
89
110
else
90
111
{
112
+ if (log)
113
+ log->PutCString (" The trivial call does not have a this pointer" );
114
+
115
+ if (log)
116
+ log->Printf (" About to write the argument (0x%llx) into RDI" , (uint64_t )arg);
117
+
91
118
if (!reg_ctx->WriteRegisterFromUnsigned (rdiID, arg))
92
119
return false ;
93
120
}
94
121
95
122
// First, align the SP
123
+
124
+ if (log)
125
+ log->Printf (" 16-byte aligning SP: 0x%llx to 0x%llx" , (uint64_t )sp, (uint64_t )(sp & ~0xfull ));
96
126
97
127
sp &= ~(0xfull ); // 16-byte alignment
98
128
@@ -101,11 +131,18 @@ ABISysV_x86_64::PrepareTrivialCall (Thread &thread,
101
131
sp -= 8 ;
102
132
uint64_t returnAddressU64 = returnAddress;
103
133
Error error;
134
+
135
+ if (log)
136
+ log->Printf (" Pushing the return address onto the stack: new SP 0x%llx, return address 0x%llx" , (uint64_t )sp, (uint64_t )returnAddressU64);
137
+
104
138
if (thread.GetProcess ().WriteMemory (sp, &returnAddressU64, sizeof (returnAddressU64), error) != sizeof (returnAddressU64))
105
139
return false ;
106
140
107
141
// %rsp is set to the actual stack value.
108
142
143
+ if (log)
144
+ log->Printf (" Writing SP (0x%llx) down" , (uint64_t )sp);
145
+
109
146
if (!reg_ctx->WriteRegisterFromUnsigned (rspID, sp))
110
147
return false ;
111
148
@@ -117,6 +154,9 @@ ABISysV_x86_64::PrepareTrivialCall (Thread &thread,
117
154
#endif
118
155
119
156
// %rip is set to the address of the called function.
157
+
158
+ if (log)
159
+ log->Printf (" Writing new IP (0x%llx) down" , (uint64_t )functionAddress);
120
160
121
161
if (!reg_ctx->WriteRegisterFromUnsigned (ripID, functionAddress))
122
162
return false ;
0 commit comments