Skip to content

Commit e609fe6

Browse files
committed
Revert "[lldb-server] jThreadsInfo returns stack memory"
This reverts commit a53bf9b.
1 parent 2a436a0 commit e609fe6

File tree

5 files changed

+2
-317
lines changed

5 files changed

+2
-317
lines changed

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp

Lines changed: 1 addition & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "lldb/Target/MemoryRegionInfo.h"
3232
#include "lldb/Utility/Args.h"
3333
#include "lldb/Utility/DataBuffer.h"
34-
#include "lldb/Utility/DataExtractor.h"
3534
#include "lldb/Utility/Endian.h"
3635
#include "lldb/Utility/LLDBAssert.h"
3736
#include "lldb/Utility/Log.h"
@@ -563,119 +562,6 @@ GetRegistersAsJSON(NativeThreadProtocol &thread) {
563562
return register_object;
564563
}
565564

566-
static llvm::Optional<RegisterValue>
567-
GetRegisterValue(NativeRegisterContext &reg_ctx, uint32_t generic_regnum) {
568-
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
569-
uint32_t reg_num = reg_ctx.ConvertRegisterKindToRegisterNumber(
570-
eRegisterKindGeneric, generic_regnum);
571-
const RegisterInfo *const reg_info_p =
572-
reg_ctx.GetRegisterInfoAtIndex(reg_num);
573-
574-
if (reg_info_p == nullptr || reg_info_p->value_regs != nullptr) {
575-
LLDB_LOGF(log, "%s failed to get register info for register index %" PRIu32,
576-
__FUNCTION__, reg_num);
577-
return {};
578-
}
579-
580-
RegisterValue reg_value;
581-
Status error = reg_ctx.ReadRegister(reg_info_p, reg_value);
582-
if (error.Fail()) {
583-
LLDB_LOGF(log, "%s failed to read register '%s' index %" PRIu32 ": %s",
584-
__FUNCTION__,
585-
reg_info_p->name ? reg_info_p->name : "<unnamed-register>",
586-
reg_num, error.AsCString());
587-
return {};
588-
}
589-
return reg_value;
590-
}
591-
592-
static json::Object CreateMemoryChunk(json::Array &stack_memory_chunks,
593-
addr_t address,
594-
std::vector<uint8_t> &bytes) {
595-
json::Object chunk;
596-
chunk.try_emplace("address", static_cast<int64_t>(address));
597-
StreamString stream;
598-
for (uint8_t b : bytes)
599-
stream.PutHex8(b);
600-
chunk.try_emplace("bytes", stream.GetString().str());
601-
return chunk;
602-
}
603-
604-
static json::Array GetStackMemoryAsJSON(NativeProcessProtocol &process,
605-
NativeThreadProtocol &thread) {
606-
uint32_t address_size = process.GetArchitecture().GetAddressByteSize();
607-
const size_t kStackTopMemoryInfoWordSize = 12;
608-
size_t stack_top_memory_info_byte_size =
609-
kStackTopMemoryInfoWordSize * address_size;
610-
const size_t kMaxStackSize = 128 * 1024;
611-
const size_t kMaxFrameSize = 4 * 1024;
612-
size_t fp_and_ra_size = 2 * address_size;
613-
const size_t kMaxFrameCount = 128;
614-
615-
NativeRegisterContext &reg_ctx = thread.GetRegisterContext();
616-
617-
json::Array stack_memory_chunks;
618-
619-
lldb::addr_t sp_value;
620-
if (llvm::Optional<RegisterValue> optional_sp_value =
621-
GetRegisterValue(reg_ctx, LLDB_REGNUM_GENERIC_SP)) {
622-
sp_value = optional_sp_value->GetAsUInt64();
623-
} else {
624-
return stack_memory_chunks;
625-
}
626-
lldb::addr_t fp_value;
627-
if (llvm::Optional<RegisterValue> optional_fp_value =
628-
GetRegisterValue(reg_ctx, LLDB_REGNUM_GENERIC_FP)) {
629-
fp_value = optional_fp_value->GetAsUInt64();
630-
} else {
631-
return stack_memory_chunks;
632-
}
633-
634-
// First, make sure we copy the top stack_top_memory_info_byte_size bytes
635-
// from the stack.
636-
size_t byte_count = std::min(stack_top_memory_info_byte_size,
637-
static_cast<size_t>(fp_value - sp_value));
638-
std::vector<uint8_t> buf(byte_count, 0);
639-
640-
size_t bytes_read = 0;
641-
Status error = process.ReadMemoryWithoutTrap(sp_value, buf.data(), byte_count,
642-
bytes_read);
643-
if (error.Success() && bytes_read > 0) {
644-
buf.resize(bytes_read);
645-
stack_memory_chunks.push_back(
646-
CreateMemoryChunk(stack_memory_chunks, sp_value, buf));
647-
}
648-
649-
// Additionally, try to walk the frame pointer link chain. If the frame
650-
// is too big or if the frame pointer points too far, stop the walk.
651-
addr_t max_frame_pointer = sp_value + kMaxStackSize;
652-
for (size_t i = 0; i < kMaxFrameCount; i++) {
653-
if (fp_value < sp_value || fp_value > sp_value + kMaxFrameSize ||
654-
fp_value > max_frame_pointer)
655-
break;
656-
657-
std::vector<uint8_t> fp_ra_buf(fp_and_ra_size, 0);
658-
bytes_read = 0;
659-
error = process.ReadMemoryWithoutTrap(fp_value, fp_ra_buf.data(),
660-
fp_and_ra_size, bytes_read);
661-
if (error.Fail() || bytes_read != fp_and_ra_size)
662-
break;
663-
664-
stack_memory_chunks.push_back(
665-
CreateMemoryChunk(stack_memory_chunks, fp_value, fp_ra_buf));
666-
667-
// Advance the stack pointer and the frame pointer.
668-
sp_value = fp_value;
669-
lldb_private::DataExtractor extractor(
670-
fp_ra_buf.data(), fp_and_ra_size,
671-
process.GetArchitecture().GetByteOrder(), address_size);
672-
offset_t offset = 0;
673-
fp_value = extractor.GetAddress(&offset);
674-
}
675-
676-
return stack_memory_chunks;
677-
}
678-
679565
static const char *GetStopReasonString(StopReason stop_reason) {
680566
switch (stop_reason) {
681567
case eStopReasonTrace:
@@ -740,9 +626,6 @@ GetJSONThreadsInfo(NativeProcessProtocol &process, bool abridged) {
740626
} else {
741627
return registers.takeError();
742628
}
743-
json::Array stack_memory = GetStackMemoryAsJSON(process, *thread);
744-
if (!stack_memory.empty())
745-
thread_obj.try_emplace("memory", std::move(stack_memory));
746629
}
747630

748631
thread_obj.try_emplace("tid", static_cast<int64_t>(tid));
@@ -947,7 +830,7 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
947830
reg_set_p->name ? reg_set_p->name : "<unnamed-set>",
948831
*reg_num_p);
949832
} else if (reg_info_p->value_regs == nullptr) {
950-
// Only expedite registers that are not contained in other registers.
833+
// Only expediate registers that are not contained in other registers.
951834
RegisterValue reg_value;
952835
Status error = reg_ctx.ReadRegister(reg_info_p, reg_value);
953836
if (error.Success()) {

lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def gather_threads_info_pcs(self, pc_register, little_endian):
158158
register = str(pc_register)
159159
# The jThreadsInfo response is not valid JSON data, so we have to
160160
# clean it up first.
161-
jthreads_info = json.loads(self.decode_gdbremote_binary(threads_info))
161+
jthreads_info = json.loads(re.sub(r"}]", "}", threads_info))
162162
thread_pcs = dict()
163163
for thread_info in jthreads_info:
164164
tid = thread_info["tid"]
@@ -167,34 +167,6 @@ def gather_threads_info_pcs(self, pc_register, little_endian):
167167

168168
return thread_pcs
169169

170-
def gather_threads_info_memory(self):
171-
self.reset_test_sequence()
172-
self.test_sequence.add_log_lines(
173-
[
174-
"read packet: $jThreadsInfo#c1",
175-
{
176-
"direction": "send",
177-
"regex": r"^\$(.*)#[0-9a-fA-F]{2}$",
178-
"capture": {
179-
1: "threads_info"}},
180-
],
181-
True)
182-
183-
context = self.expect_gdbremote_sequence()
184-
self.assertIsNotNone(context)
185-
threads_info = context.get("threads_info")
186-
# The jThreadsInfo response is not valid JSON data, so we have to
187-
# clean it up first.
188-
jthreads_info = json.loads(self.decode_gdbremote_binary(threads_info))
189-
# Collect all the memory chunks from all threads
190-
memory_chunks = dict()
191-
for thread_info in jthreads_info:
192-
chunk_list = thread_info["memory"]
193-
self.assertNotEqual(len(chunk_list), 0)
194-
for chunk in chunk_list:
195-
memory_chunks[chunk["address"]] = chunk["bytes"]
196-
return memory_chunks
197-
198170
def QListThreadsInStopReply_supported(self):
199171
procs = self.prep_debug_monitor_and_inferior()
200172
self.test_sequence.add_log_lines(
@@ -341,45 +313,3 @@ def test_stop_reply_contains_thread_pcs_debugserver(self):
341313
self.build()
342314
self.set_inferior_startup_launch()
343315
self.stop_reply_contains_thread_pcs(5)
344-
345-
def read_memory_chunk(self, address, length):
346-
self.test_sequence.add_log_lines(
347-
["read packet: $x{0:x},{1:x}#00".format(address, length),
348-
{
349-
"direction": "send",
350-
"regex": r"^\$([\s\S]*)#[0-9a-fA-F]{2}$",
351-
"capture": {
352-
1: "contents"}},
353-
],
354-
True)
355-
contents = self.expect_gdbremote_sequence()["contents"]
356-
contents = self.decode_gdbremote_binary(contents)
357-
hex_contents = ""
358-
for c in contents:
359-
hex_contents += "%02x" % ord(c)
360-
return hex_contents
361-
362-
def check_memory_chunks_equal(self, memory_chunks):
363-
self.reset_test_sequence()
364-
for address in memory_chunks:
365-
contents = memory_chunks[address]
366-
byte_size = len(contents) // 2
367-
mem = self.read_memory_chunk(address, byte_size)
368-
self.assertEqual(mem, contents)
369-
370-
def stop_reply_thread_info_correct_memory(self, thread_count):
371-
# Run and stop the program.
372-
self.gather_stop_reply_fields([], thread_count, [])
373-
# Read memory chunks from jThreadsInfo.
374-
memory_chunks = self.gather_threads_info_memory()
375-
# Check the chunks are correct.
376-
self.check_memory_chunks_equal(memory_chunks)
377-
378-
@expectedFailureAll(oslist=["windows"])
379-
@skipIfNetBSD
380-
@llgs_test
381-
def test_stop_reply_thread_info_correct_memory_llgs(self):
382-
self.init_llgs_test()
383-
self.build()
384-
self.set_inferior_startup_launch()
385-
self.stop_reply_thread_info_correct_memory(5)

lldb/test/API/tools/lldb-server/threads-info/Makefile

Lines changed: 0 additions & 3 deletions
This file was deleted.

lldb/test/API/tools/lldb-server/threads-info/TestGdbRemoteThreadsInfoMemory.py

Lines changed: 0 additions & 98 deletions
This file was deleted.

lldb/test/API/tools/lldb-server/threads-info/main.cpp

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)