Index: source/Commands/CommandObjectMemory.cpp =================================================================== --- source/Commands/CommandObjectMemory.cpp +++ source/Commands/CommandObjectMemory.cpp @@ -70,20 +70,20 @@ ~OptionGroupReadMemory () override { } - - + + uint32_t GetNumDefinitions () override { return sizeof (g_option_table) / sizeof (OptionDefinition); } - + const OptionDefinition* GetDefinitions () override { return g_option_table; } - + Error SetOptionValue (CommandInterpreter &interpreter, uint32_t option_idx, @@ -91,7 +91,7 @@ { Error error; const int short_option = g_option_table[option_idx].short_option; - + switch (short_option) { case 'l': @@ -103,22 +103,22 @@ case 'b': m_output_as_binary = true; break; - + case 't': error = m_view_as_type.SetValueFromString (option_arg); break; - + case 'r': m_force = true; break; - + default: error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option); break; } return error; } - + void OptionParsingStarting (CommandInterpreter &interpreter) override { @@ -127,7 +127,7 @@ m_view_as_type.Clear(); m_force = false; } - + Error FinalizeSettings (Target *target, OptionGroupFormat& format_options) { @@ -137,12 +137,12 @@ const bool byte_size_option_set = byte_size_value.OptionWasSet(); const bool num_per_line_option_set = m_num_per_line.OptionWasSet(); const bool count_option_set = format_options.GetCountValue().OptionWasSet(); - + switch (format_options.GetFormat()) { default: break; - + case eFormatBoolean: if (!byte_size_option_set) byte_size_value = 1; @@ -151,7 +151,7 @@ if (!count_option_set) format_options.GetCountValue() = 8; break; - + case eFormatCString: break; @@ -176,7 +176,7 @@ if (!count_option_set) format_options.GetCountValue() = 8; break; - + case eFormatBinary: case eFormatFloat: case eFormatOctal: @@ -193,7 +193,7 @@ if (!count_option_set) format_options.GetCountValue() = 8; break; - + case eFormatBytes: case eFormatBytesWithASCII: if (byte_size_option_set) @@ -261,7 +261,7 @@ if (!count_option_set) count_value = 8; break; - + case eFormatVectorOfChar: case eFormatVectorOfSInt8: case eFormatVectorOfUInt8: @@ -293,7 +293,7 @@ m_output_as_binary || m_view_as_type.OptionWasSet(); } - + OptionValueUInt64 m_num_per_line; bool m_output_as_binary; OptionValueString m_view_as_type; @@ -331,35 +331,35 @@ CommandArgumentEntry arg2; CommandArgumentData start_addr_arg; CommandArgumentData end_addr_arg; - + // Define the first (and only) variant of this arg. start_addr_arg.arg_type = eArgTypeAddressOrExpression; start_addr_arg.arg_repetition = eArgRepeatPlain; - + // There is only one variant this argument could be; put it into the argument entry. arg1.push_back (start_addr_arg); - + // Define the first (and only) variant of this arg. end_addr_arg.arg_type = eArgTypeAddressOrExpression; end_addr_arg.arg_repetition = eArgRepeatOptional; - + // There is only one variant this argument could be; put it into the argument entry. arg2.push_back (end_addr_arg); - + // Push the data for the first argument into the m_arguments vector. m_arguments.push_back (arg1); m_arguments.push_back (arg2); - + // Add the "--format" and "--count" options to group 1 and 3 - m_option_group.Append (&m_format_options, - OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_COUNT, + m_option_group.Append (&m_format_options, + OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_COUNT, LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3); - m_option_group.Append (&m_format_options, - OptionGroupFormat::OPTION_GROUP_GDB_FMT, + m_option_group.Append (&m_format_options, + OptionGroupFormat::OPTION_GROUP_GDB_FMT, LLDB_OPT_SET_1 | LLDB_OPT_SET_3); // Add the "--size" option to group 1 and 2 - m_option_group.Append (&m_format_options, - OptionGroupFormat::OPTION_GROUP_SIZE, + m_option_group.Append (&m_format_options, + OptionGroupFormat::OPTION_GROUP_SIZE, LLDB_OPT_SET_1 | LLDB_OPT_SET_2); m_option_group.Append (&m_memory_options); m_option_group.Append (&m_outfile_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3); @@ -400,21 +400,21 @@ return false; } - CompilerType clang_ast_type; + CompilerType clang_ast_type; Error error; const char *view_as_type_cstr = m_memory_options.m_view_as_type.GetCurrentValue(); if (view_as_type_cstr && view_as_type_cstr[0]) { // We are viewing memory as a type - + SymbolContext sc; const bool exact_match = false; TypeList type_list; uint32_t reference_count = 0; uint32_t pointer_count = 0; size_t idx; - + #define ALL_KEYWORDS \ KEYWORD("const") \ KEYWORD("volatile") \ @@ -422,7 +422,7 @@ KEYWORD("struct") \ KEYWORD("class") \ KEYWORD("union") - + #define KEYWORD(s) s, static const char *g_keywords[] = { @@ -436,18 +436,18 @@ ALL_KEYWORDS }; #undef KEYWORD - + #undef ALL_KEYWORDS - + static size_t g_num_keywords = sizeof(g_keywords) / sizeof(const char *); std::string type_str(view_as_type_cstr); - + // Remove all instances of g_keywords that are followed by spaces for (size_t i = 0; i < g_num_keywords; ++i) { const char *keyword = g_keywords[i]; int keyword_len = g_keyword_lengths[i]; - + idx = 0; while ((idx = type_str.find (keyword, idx)) != std::string::npos) { @@ -463,7 +463,7 @@ } } bool done = type_str.empty(); - // + // idx = type_str.find_first_not_of (" \t"); if (idx > 0 && idx != std::string::npos) type_str.erase (0, idx); @@ -504,7 +504,7 @@ } } } - + ConstString lookup_type_name(type_str.c_str()); StackFrame *frame = m_exe_ctx.GetFramePtr(); if (frame) @@ -515,32 +515,32 @@ sc.module_sp->FindTypes (sc, lookup_type_name, exact_match, - 1, + 1, type_list); } } if (type_list.GetSize() == 0) { - target->GetImages().FindTypes (sc, - lookup_type_name, - exact_match, - 1, + target->GetImages().FindTypes (sc, + lookup_type_name, + exact_match, + 1, type_list); } - + if (type_list.GetSize() == 0 && lookup_type_name.GetCString() && *lookup_type_name.GetCString() == '$') { if (ClangPersistentVariables *persistent_vars = llvm::dyn_cast_or_null(target->GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC))) { clang::TypeDecl *tdecl = persistent_vars->GetPersistentType(ConstString(lookup_type_name)); - + if (tdecl) { clang_ast_type.SetCompilerType(ClangASTContext::GetASTContext(&tdecl->getASTContext()),(const lldb::opaque_compiler_type_t)tdecl->getTypeForDecl()); } } } - + if (clang_ast_type.IsValid() == false) { if (type_list.GetSize() == 0) @@ -557,7 +557,7 @@ clang_ast_type = type_sp->GetFullCompilerType (); } } - + while (pointer_count > 0) { CompilerType pointer_type = clang_ast_type.GetPointerType(); @@ -573,15 +573,15 @@ } m_format_options.GetByteSizeValue() = clang_ast_type.GetByteSize(nullptr); - + if (m_format_options.GetByteSizeValue() == 0) { - result.AppendErrorWithFormat ("unable to get the byte size of the type '%s'\n", + result.AppendErrorWithFormat ("unable to get the byte size of the type '%s'\n", view_as_type_cstr); result.SetStatus(eReturnStatusFailed); return false; } - + if (!m_format_options.GetCountValue().OptionWasSet()) m_format_options.GetCountValue() = 1; } @@ -678,7 +678,7 @@ } uint32_t max_unforced_size = target->GetMaximumMemReadSize(); - + if (total_byte_size > max_unforced_size && !m_memory_options.m_force) { result.AppendErrorWithFormat("Normally, \'memory read\' will not read over %" PRIu32 " bytes of data.\n",max_unforced_size); @@ -686,7 +686,7 @@ result.AppendErrorWithFormat("or set target.max-memory-read-size if you will often need a larger limit.\n"); return false; } - + DataBufferSP data_sp; size_t bytes_read = 0; if (clang_ast_type.GetOpaqueQualType()) @@ -723,7 +723,7 @@ result.SetStatus(eReturnStatusFailed); return false; } - + if (bytes_read < total_byte_size) result.AppendWarningWithFormat("Not all bytes (%" PRIu64 "/%" PRIu64 ") were able to be read from 0x%" PRIx64 ".\n", (uint64_t)bytes_read, (uint64_t)total_byte_size, addr); } @@ -760,7 +760,7 @@ result.SetStatus(eReturnStatusFailed); return false; } - + if (item_byte_size == read) { result.AppendWarningWithFormat("unable to find a NULL terminated string at 0x%" PRIx64 ".Consider increasing the maximum read length.\n", data_addr); @@ -769,13 +769,13 @@ } else ++read; // account for final NULL byte - + memcpy(data_ptr, &buffer[0], read); data_ptr += read; data_addr += read; bytes_read += read; item_count++; // if we break early we know we only read item_count strings - + if (break_on_no_NULL) break; } @@ -797,12 +797,12 @@ { char path[PATH_MAX]; outfile_spec.GetPath (path, sizeof(path)); - + uint32_t open_options = File::eOpenOptionWrite | File::eOpenOptionCanCreate; const bool append = m_outfile_options.GetAppend().GetCurrentValue(); if (append) open_options |= File::eOpenOptionAppend; - + if (outfile_stream.GetFile ().Open (path, open_options).Success()) { if (m_memory_options.m_output_as_binary) @@ -810,13 +810,13 @@ const size_t bytes_written = outfile_stream.Write (data_sp->GetBytes(), bytes_read); if (bytes_written > 0) { - result.GetOutputStream().Printf ("%zi bytes %s to '%s'\n", - bytes_written, - append ? "appended" : "written", + result.GetOutputStream().Printf ("%zi bytes %s to '%s'\n", + bytes_written, + append ? "appended" : "written", path); return true; } - else + else { result.AppendErrorWithFormat("Failed to write %" PRIu64 " bytes to '%s'.\n", (uint64_t)bytes_read, path); result.SetStatus(eReturnStatusFailed); @@ -830,14 +830,14 @@ output_stream = &outfile_stream; } } - else + else { result.AppendErrorWithFormat("Failed to open file '%s' for %s.\n", path, append ? "append" : "write"); result.SetStatus(eReturnStatusFailed); return false; } } - else + else { output_stream = &result.GetOutputStream(); } @@ -852,9 +852,9 @@ Address address (item_addr); StreamString name_strm; name_strm.Printf ("0x%" PRIx64, item_addr); - ValueObjectSP valobj_sp (ValueObjectMemory::Create (exe_scope, - name_strm.GetString().c_str(), - address, + ValueObjectSP valobj_sp (ValueObjectMemory::Create (exe_scope, + name_strm.GetString().c_str(), + address, clang_ast_type)); if (valobj_sp) { @@ -863,13 +863,13 @@ valobj_sp->SetFormat (format); DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions(eLanguageRuntimeDescriptionDisplayVerbosityFull,format)); - + valobj_sp->Dump(*output_stream,options); } else { - result.AppendErrorWithFormat ("failed to create a value object for: (%s) %s\n", - view_as_type_cstr, + result.AppendErrorWithFormat ("failed to create a value object for: (%s) %s\n", + view_as_type_cstr, name_strm.GetString().c_str()); result.SetStatus(eReturnStatusFailed); return false; @@ -879,11 +879,11 @@ } result.SetStatus(eReturnStatusSuccessFinishResult); - DataExtractor data (data_sp, - target->GetArchitecture().GetByteOrder(), + DataExtractor data (data_sp, + target->GetArchitecture().GetByteOrder(), target->GetArchitecture().GetAddressByteSize(), target->GetArchitecture().GetDataByteSize()); - + Format format = m_format_options.GetFormat(); if ( ( (format == eFormatChar) || (format == eFormatCharPrintable) ) && (item_byte_size != 1)) @@ -932,7 +932,7 @@ OptionGroupOutputFile m_outfile_options; OptionGroupValueObjectDisplay m_varobj_options; lldb::addr_t m_next_addr; - lldb::addr_t m_prev_byte_size; + lldb::addr_t m_prev_byte_size; OptionGroupFormat m_prev_format_options; OptionGroupReadMemory m_prev_memory_options; OptionGroupOutputFile m_prev_outfile_options; @@ -955,7 +955,7 @@ class CommandObjectMemoryFind : public CommandObjectParsed { public: - + class OptionGroupFindMemory : public OptionGroup { public: @@ -965,23 +965,23 @@ m_offset(0) { } - + ~OptionGroupFindMemory () override { } - + uint32_t GetNumDefinitions () override { return sizeof (g_memory_find_option_table) / sizeof (OptionDefinition); } - + const OptionDefinition* GetDefinitions () override { return g_memory_find_option_table; } - + Error SetOptionValue (CommandInterpreter &interpreter, uint32_t option_idx, @@ -989,22 +989,22 @@ { Error error; const int short_option = g_memory_find_option_table[option_idx].short_option; - + switch (short_option) { case 'e': m_expr.SetValueFromString(option_arg); break; - + case 's': m_string.SetValueFromString(option_arg); break; - + case 'c': if (m_count.SetValueFromString(option_arg).Fail()) error.SetErrorString("unrecognized value for count"); break; - + case 'o': if (m_offset.SetValueFromString(option_arg).Fail()) error.SetErrorString("unrecognized value for dump-offset"); @@ -1016,7 +1016,7 @@ } return error; } - + void OptionParsingStarting (CommandInterpreter &interpreter) override { @@ -1024,13 +1024,13 @@ m_string.Clear(); m_count.Clear(); } - + OptionValueString m_expr; OptionValueString m_string; OptionValueUInt64 m_count; OptionValueUInt64 m_offset; }; - + CommandObjectMemoryFind (CommandInterpreter &interpreter) : CommandObjectParsed (interpreter, "memory find", @@ -1044,39 +1044,39 @@ CommandArgumentEntry arg2; CommandArgumentData addr_arg; CommandArgumentData value_arg; - + // Define the first (and only) variant of this arg. addr_arg.arg_type = eArgTypeAddressOrExpression; addr_arg.arg_repetition = eArgRepeatPlain; - + // There is only one variant this argument could be; put it into the argument entry. arg1.push_back (addr_arg); - + // Define the first (and only) variant of this arg. value_arg.arg_type = eArgTypeAddressOrExpression; value_arg.arg_repetition = eArgRepeatPlain; - + // There is only one variant this argument could be; put it into the argument entry. arg2.push_back (value_arg); - + // Push the data for the first argument into the m_arguments vector. m_arguments.push_back (arg1); m_arguments.push_back (arg2); - + m_option_group.Append (&m_memory_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_2); m_option_group.Finalize(); } - + ~CommandObjectMemoryFind () override { } - + Options * GetOptions () override { return &m_option_group; } - + protected: bool DoExecute (Args& command, CommandReturnObject &result) override @@ -1111,11 +1111,11 @@ result.AppendError("starting address must be smaller than ending address"); return false; } - + lldb::addr_t found_location = LLDB_INVALID_ADDRESS; - + DataBufferHeap buffer; - + if (m_memory_options.m_string.OptionWasSet()) buffer.CopyData(m_memory_options.m_string.GetStringValue(), strlen(m_memory_options.m_string.GetStringValue())); else if (m_memory_options.m_expr.OptionWasSet()) @@ -1169,7 +1169,7 @@ result.AppendError("please pass either a block of text, or an expression to evaluate."); return false; } - + size_t count = m_memory_options.m_count.GetCurrentValue(); found_location = low_addr; bool ever_found = false; @@ -1202,11 +1202,11 @@ found_location++; ever_found = true; } - + result.SetStatus(lldb::eReturnStatusSuccessFinishResult); return true; } - + lldb::addr_t Search (lldb::addr_t low, lldb::addr_t high, @@ -1228,7 +1228,7 @@ } return LLDB_INVALID_ADDRESS; } - + OptionGroupOptions m_option_group; OptionGroupFindMemory m_memory_options; }; @@ -1265,13 +1265,13 @@ { return sizeof (g_memory_write_option_table) / sizeof (OptionDefinition); } - + const OptionDefinition* GetDefinitions () override { return g_memory_write_option_table; } - + Error SetOptionValue (CommandInterpreter &interpreter, uint32_t option_idx, @@ -1279,7 +1279,7 @@ { Error error; const int short_option = g_memory_write_option_table[option_idx].short_option; - + switch (short_option) { case 'i': @@ -1290,7 +1290,7 @@ error.SetErrorStringWithFormat("input file does not exist: '%s'", option_arg); } break; - + case 'o': { bool success; @@ -1301,14 +1301,14 @@ } } break; - + default: error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option); break; } return error; } - + void OptionParsingStarting (CommandInterpreter &interpreter) override { @@ -1334,25 +1334,25 @@ CommandArgumentEntry arg2; CommandArgumentData addr_arg; CommandArgumentData value_arg; - + // Define the first (and only) variant of this arg. addr_arg.arg_type = eArgTypeAddress; addr_arg.arg_repetition = eArgRepeatPlain; - + // There is only one variant this argument could be; put it into the argument entry. arg1.push_back (addr_arg); - + // Define the first (and only) variant of this arg. value_arg.arg_type = eArgTypeValue; value_arg.arg_repetition = eArgRepeatPlus; - + // There is only one variant this argument could be; put it into the argument entry. arg2.push_back (value_arg); - + // Push the data for the first argument into the m_arguments vector. m_arguments.push_back (arg1); m_arguments.push_back (arg2); - + m_option_group.Append (&m_format_options, OptionGroupFormat::OPTION_GROUP_FORMAT, LLDB_OPT_SET_1); m_option_group.Append (&m_format_options, OptionGroupFormat::OPTION_GROUP_SIZE , LLDB_OPT_SET_1|LLDB_OPT_SET_2); m_option_group.Append (&m_memory_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_2); @@ -1413,7 +1413,7 @@ result.AppendErrorWithFormat ("%s takes a destination address when writing file contents.\n", m_cmd_name.c_str()); result.SetStatus(eReturnStatusFailed); return false; - } + } } else if (argc < 2) { @@ -1442,7 +1442,7 @@ result.SetStatus(eReturnStatusFailed); return false; } - + if (m_memory_options.m_infile) { size_t length = SIZE_MAX; @@ -1456,7 +1456,7 @@ { Error error; size_t bytes_written = process->WriteMemory (addr, data_sp->GetBytes(), length, error); - + if (bytes_written == length) { // All bytes written @@ -1469,7 +1469,7 @@ result.GetOutputStream().Printf("%" PRIu64 " bytes of %" PRIu64 " requested were written to 0x%" PRIx64 "\n", (uint64_t)bytes_written, (uint64_t)length, addr); result.SetStatus(eReturnStatusSuccessFinishResult); } - else + else { result.AppendErrorWithFormat ("Memory write to 0x%" PRIx64 " failed: %s.\n", addr, error.AsCString()); result.SetStatus(eReturnStatusFailed); @@ -1519,6 +1519,7 @@ case eFormatVectorOfUInt32: case eFormatVectorOfSInt64: case eFormatVectorOfUInt64: + case eFormatVectorOfFloat16: case eFormatVectorOfFloat32: case eFormatVectorOfFloat64: case eFormatVectorOfUInt128: @@ -1537,7 +1538,7 @@ case eFormatHex: case eFormatHexUppercase: case eFormatPointer: - + // Decode hex bytes uval64 = StringConvert::ToUInt64(value_str, UINT64_MAX, 16, &success); if (!success) @@ -1685,7 +1686,7 @@ class CommandObjectMemoryHistory : public CommandObjectParsed { public: - + CommandObjectMemoryHistory (CommandInterpreter &interpreter) : CommandObjectParsed (interpreter, "memory history", @@ -1695,47 +1696,47 @@ { CommandArgumentEntry arg1; CommandArgumentData addr_arg; - + // Define the first (and only) variant of this arg. addr_arg.arg_type = eArgTypeAddress; addr_arg.arg_repetition = eArgRepeatPlain; - + // There is only one variant this argument could be; put it into the argument entry. arg1.push_back (addr_arg); - + // Push the data for the first argument into the m_arguments vector. m_arguments.push_back (arg1); } - + ~CommandObjectMemoryHistory () override { } - + const char * GetRepeatCommand (Args ¤t_command_args, uint32_t index) override { return m_cmd_name.c_str(); } - + protected: bool DoExecute (Args& command, CommandReturnObject &result) override { const size_t argc = command.GetArgumentCount(); - + if (argc == 0 || argc > 1) { result.AppendErrorWithFormat ("%s takes an address expression", m_cmd_name.c_str()); result.SetStatus(eReturnStatusFailed); return false; } - + Error error; lldb::addr_t addr = Args::StringToAddress (&m_exe_ctx, command.GetArgumentAtIndex(0), LLDB_INVALID_ADDRESS, &error); - + if (addr == LLDB_INVALID_ADDRESS) { result.AppendError("invalid address expression"); @@ -1743,30 +1744,30 @@ result.SetStatus(eReturnStatusFailed); return false; } - + Stream *output_stream = &result.GetOutputStream(); - + const ProcessSP &process_sp = m_exe_ctx.GetProcessSP(); const MemoryHistorySP &memory_history = MemoryHistory::FindPlugin(process_sp); - + if (! memory_history.get()) { result.AppendError("no available memory history provider"); result.SetStatus(eReturnStatusFailed); return false; } - + HistoryThreads thread_list = memory_history->GetHistoryThreads(addr); - + for (auto thread : thread_list) { thread->GetStatus(*output_stream, 0, UINT32_MAX, 0); } - + result.SetStatus(eReturnStatusSuccessFinishResult); - + return true; } - + }; Index: tools/debugserver/source/RNBRemote.cpp =================================================================== --- tools/debugserver/source/RNBRemote.cpp +++ tools/debugserver/source/RNBRemote.cpp @@ -404,7 +404,7 @@ { if (buf_size == 0) return rnb_success; - + std::string packet("A"); packet.append(buf, buf_size); return SendPacket(packet); @@ -413,13 +413,13 @@ // Given a std::string packet contents to send, possibly encode/compress it. // If compression is enabled, the returned std::string will be in one of two // forms: -// +// // N // C: // // If compression is not requested, the original packet contents are returned -std::string +std::string RNBRemote::CompressString (const std::string &orig) { std::string compressed; @@ -442,7 +442,7 @@ #if defined (HAVE_LIBCOMPRESSION) if (compression_decode_buffer && compression_type == compression_types::lz4) { - compressed_size = compression_encode_buffer (encoded_data.data(), + compressed_size = compression_encode_buffer (encoded_data.data(), encoded_data_buf_size, (uint8_t*) orig.c_str(), orig.size(), @@ -451,7 +451,7 @@ } if (compression_decode_buffer && compression_type == compression_types::zlib_deflate) { - compressed_size = compression_encode_buffer (encoded_data.data(), + compressed_size = compression_encode_buffer (encoded_data.data(), encoded_data_buf_size, (uint8_t*) orig.c_str(), orig.size(), @@ -460,7 +460,7 @@ } if (compression_decode_buffer && compression_type == compression_types::lzma) { - compressed_size = compression_encode_buffer (encoded_data.data(), + compressed_size = compression_encode_buffer (encoded_data.data(), encoded_data_buf_size, (uint8_t*) orig.c_str(), orig.size(), @@ -469,7 +469,7 @@ } if (compression_decode_buffer && compression_type == compression_types::lzfse) { - compressed_size = compression_encode_buffer (encoded_data.data(), + compressed_size = compression_encode_buffer (encoded_data.data(), encoded_data_buf_size, (uint8_t*) orig.c_str(), orig.size(), @@ -1003,7 +1003,7 @@ #if defined (__arm__) || defined (__arm64__) || defined (__aarch64__) struct sched_param thread_param; int thread_sched_policy; - if (pthread_getschedparam(pthread_self(), &thread_sched_policy, &thread_param) == 0) + if (pthread_getschedparam(pthread_self(), &thread_sched_policy, &thread_param) == 0) { thread_param.sched_priority = 47; pthread_setschedparam(pthread_self(), thread_sched_policy, &thread_param); @@ -1025,7 +1025,6 @@ case rnb_success: break; - default: case rnb_err: DNBLogThreadedIf (LOG_RNB_REMOTE, "RNBSocket::GetCommData returned error %u", err); done = true; @@ -1058,11 +1057,11 @@ if (sizeof (char *) == 8) { return CPU_TYPE_ARM64; - } + } else { return CPU_TYPE_ARM; - } + } #elif defined (__i386__) || defined (__x86_64__) if (sizeof (char*) == 8) { @@ -1079,7 +1078,7 @@ /* Read the bytes in STR which are GDB Remote Protocol binary encoded bytes (8-bit bytes). - This encoding uses 0x7d ('}') as an escape character for + This encoding uses 0x7d ('}') as an escape character for 0x7d ('}'), 0x23 ('#'), 0x24 ('$'), 0x2a ('*'). LEN is the number of bytes to be processed. If a character is escaped, it is 2 characters for LEN. A LEN of -1 means decode-until-nul-byte @@ -1227,7 +1226,8 @@ register_map_entry_t reg_entry = { regnum++, // register number starts at zero and goes up with no gaps reg_data_offset, // Offset into register context data, no gaps between registers - reg_sets[set].registers[reg] // DNBRegisterInfo + reg_sets[set].registers[reg], // DNBRegisterInfo + {} }; name_to_regnum[reg_entry.nub_info.name] = reg_entry.debugserver_regnum; @@ -1240,7 +1240,7 @@ g_dynamic_register_map.push_back (reg_entry); } } - + // Now we must find any registers whose values are in other registers and fix up // the offsets since we removed all gaps... for (auto ®_entry: g_dynamic_register_map) @@ -1265,7 +1265,7 @@ } } } - + if (new_offset != UINT32_MAX) { reg_entry.offset = new_offset; @@ -1291,8 +1291,8 @@ } } } - - + + // for (auto ®_entry: g_dynamic_register_map) // { // DNBLogThreaded("%4i: size = %3u, pseudo = %i, name = %s", @@ -1833,7 +1833,7 @@ case GENERIC_REGNUM_ARG8: ostrm << "generic:arg8;"; break; default: break; } - + if (!reg_entry->value_regnums.empty()) { ostrm << "container-regs:"; @@ -1889,10 +1889,10 @@ p++; // to regenerate the LOG_ entries (not including the LOG_RNB entries) -// $ for logname in `grep '^#define LOG_' DNBDefs.h | egrep -v 'LOG_HI|LOG_LO' | awk '{print $2}'` -// do +// $ for logname in `grep '^#define LOG_' DNBDefs.h | egrep -v 'LOG_HI|LOG_LO' | awk '{print $2}'` +// do // echo " else if (strncmp (p, \"$logname\", sizeof (\"$logname\") - 1) == 0)" -// echo " {" +// echo " {" // echo " p += sizeof (\"$logname\") - 1;" // echo " bitmask |= $logname;" // echo " }" @@ -2202,7 +2202,7 @@ char ch = packet.GetChar(); while (packet.GetChar() != ':') /* Do nothing. */; - + switch (ch) { case 'I': // STDIN @@ -2230,7 +2230,7 @@ return SendPacket ("E58"); } -rnb_err_t +rnb_err_t RNBRemote::HandlePacket_QSetWorkingDir (const char *p) { // Only set the working directory if we don't already have a process @@ -2297,7 +2297,7 @@ return HandlePacket_ILLFORMED (__FILE__, __LINE__, p, "Invalid value for QSetDetachOnError - should be 0 or 1"); break; } - + m_ctx.SetDetachOnError(should_detach); return SendPacket ("OK"); } @@ -2393,12 +2393,12 @@ The VARIABLE=VALUE part is sent hex-encoded so characters like '#' with special meaning in the remote protocol won't break it. */ - - DNBLogThreadedIf (LOG_RNB_REMOTE, "%8u RNBRemote::%s Handling QEnvironmentHexEncoded: \"%s\"", + + DNBLogThreadedIf (LOG_RNB_REMOTE, "%8u RNBRemote::%s Handling QEnvironmentHexEncoded: \"%s\"", (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__, p); p += sizeof ("QEnvironmentHexEncoded:") - 1; - + std::string arg; const char *c; c = p; @@ -2424,7 +2424,7 @@ RNBContext& ctx = Context(); if (arg.length() > 0) - ctx.PushEnvironment (arg.c_str()); + ctx.PushEnvironment (arg.c_str()); return SendPacket ("OK"); } @@ -2504,7 +2504,7 @@ if (DNBThreadGetRegisterValueByID (pid, tid, reg->nub_info.set, reg->nub_info.reg, ®_value)) reg_value_ptr = ®_value; } - + if (reg_value_ptr) { append_hex_value (ostrm, reg_value_ptr->value.v_uint8, reg->nub_info.size, false); @@ -2684,7 +2684,7 @@ if (thread_name && thread_name[0]) { size_t thread_name_len = strlen(thread_name); - + if (::strcspn (thread_name, "$#+-;:") == thread_name_len) ostrm << std::hex << "name:" << thread_name << ';'; @@ -2795,7 +2795,7 @@ } } } - + if (did_exec) { ostrm << "reason:exec;"; @@ -2891,7 +2891,7 @@ strncpy (pid_exited_packet, "W00", sizeof(pid_exited_packet)-1); pid_exited_packet[sizeof(pid_exited_packet)-1] = '\0'; } - + const char *exit_info = DNBProcessGetExitInfo (pid); if (exit_info != NULL && *exit_info != '\0') { @@ -3053,7 +3053,7 @@ // ADDR and LEN are both base 16. // Responds with 'OK' for zero-length request -// or +// or // // DATA // @@ -3244,7 +3244,7 @@ StringExtractor packet(p); packet.SetFilePos(1); // Skip the 'G' - + nub_process_t pid = m_ctx.ProcessID(); nub_thread_t tid = ExtractThreadIDFromThreadSuffix (p); if (tid == INVALID_NUB_THREAD) @@ -3257,7 +3257,7 @@ // Now allocate enough space for the entire register context std::vector reg_ctx; reg_ctx.resize(reg_ctx_size); - + const nub_size_t bytes_extracted = packet.GetHexBytes (®_ctx[0], reg_ctx.size(), 0xcc); if (bytes_extracted == reg_ctx.size()) { @@ -3265,7 +3265,7 @@ reg_ctx_size = DNBThreadSetRegisterContext(pid, tid, reg_ctx.data(), reg_ctx.size()); if (reg_ctx_size == reg_ctx.size()) return SendPacket ("OK"); - else + else return SendPacket ("E55"); } else @@ -3293,7 +3293,7 @@ } -// FORMAT: _MXXXXXX,PPP +// FORMAT: _MXXXXXX,PPP // XXXXXX: big endian hex chars // PPP: permissions can be any combo of r w x chars // @@ -3311,7 +3311,7 @@ { StringExtractor packet (p); packet.SetFilePos(2); // Skip the "_M" - + nub_addr_t size = packet.GetHexMaxU64 (StringExtractor::BigEndian, 0); if (size != 0) { @@ -3330,7 +3330,7 @@ default: success = false; break; } } - + if (success) { nub_addr_t addr = DNBProcessMemoryAllocate (m_ctx.ProcessID(), size, permissions); @@ -3346,14 +3346,14 @@ return SendPacket ("E53"); } -// FORMAT: _mXXXXXX +// FORMAT: _mXXXXXX // XXXXXX: address that was previously allocated // // RESPONSE: XXXXXX // OK: address was deallocated // EXX: error code // -// EXAMPLES: +// EXAMPLES: // _m123000 rnb_err_t @@ -3397,7 +3397,7 @@ else return HandlePacket_ILLFORMED (__FILE__, __LINE__, p, "No thread was is set with the Hg packet"); } - + // Get the register context size first by calling with NULL buffer const uint32_t save_id = DNBThreadSaveRegisterState(pid, tid); if (save_id != 0) @@ -3437,11 +3437,11 @@ else return HandlePacket_ILLFORMED (__FILE__, __LINE__, p, "No thread was is set with the Hg packet"); } - + StringExtractor packet (p); packet.SetFilePos(strlen("QRestoreRegisterState:")); // Skip the "QRestoreRegisterState:" const uint32_t save_id = packet.GetU32(0); - + if (save_id != 0) { // Get the register context size first by calling with NULL buffer @@ -3624,7 +3624,7 @@ nub_process_t pid_attaching_to = INVALID_NUB_PROCESS; // pid_attaching_to is the original pid specified char err_str[1024]={'\0'}; std::string attach_name; - + if (strstr (p, "vAttachWait;") == p) { p += strlen("vAttachWait;"); @@ -3703,7 +3703,7 @@ if (csr_check(CSR_ALLOW_TASK_FOR_PID) != 0) { bool attach_failed_due_to_sip = false; - + if (rootless_allows_task_for_pid (pid_attaching_to) == 0) { attach_failed_due_to_sip = true; @@ -3726,7 +3726,7 @@ } } } - + #endif SendPacket ("E01"); // E01 is our magic error value for attach failed. @@ -4078,13 +4078,13 @@ { /* This packet will find memory attributes (e.g. readable, writable, executable, stack, jitted code) for the memory region containing a given address and return that information. - - Users of this packet must be prepared for three results: + + Users of this packet must be prepared for three results: Region information is returned Region information is unavailable for this address because the address is in unmapped memory Region lookup cannot be performed on this platform or process is not yet launched - This packet isn't implemented + This packet isn't implemented Examples of use: qMemoryRegionInfo:3a55140 @@ -4124,11 +4124,11 @@ if (region_info.size > 0) ostrm << "size:" << std::hex << region_info.size << ';'; - + if (region_info.permissions) { ostrm << "permissions:"; - + if (region_info.permissions & eMemoryPermissionsReadable) ostrm << 'r'; if (region_info.permissions & eMemoryPermissionsWritable) @@ -4147,7 +4147,7 @@ nub_process_t pid = m_ctx.ProcessID(); if (pid == INVALID_NUB_PROCESS) return SendPacket ("OK"); - + StringExtractor packet(p += sizeof ("qGetProfileData")); DNBProfileDataScanType scan_type = eProfileAll; std::string name; @@ -4164,7 +4164,7 @@ } } } - + std::string data = DNBProcessGetProfileData(pid, scan_type); if (!data.empty()) { @@ -4210,12 +4210,12 @@ } } } - + if (interval_usec == 0) { enable = 0; } - + DNBProcessSetEnableAsyncProfiling(pid, enable, interval_usec, scan_type); return SendPacket ("OK"); } @@ -4225,7 +4225,7 @@ // type: must be a type previously reported by the qXfer:features: SupportedCompressions list // // minsize: is optional; by default the qXfer:features: DefaultCompressionMinSize value is used -// debugserver may have a better idea of what a good minimum packet size to compress is than lldb. +// debugserver may have a better idea of what a good minimum packet size to compress is than lldb. rnb_err_t RNBRemote::HandlePacket_QEnableCompression (const char *p) @@ -4313,7 +4313,7 @@ RNBRemote::HandlePacket_WatchpointSupportInfo (const char *p) { /* This packet simply returns the number of supported hardware watchpoints. - + Examples of use: qWatchpointSupportInfo: num:4 @@ -4554,7 +4554,7 @@ static uint32_t g_host_cpusubtype = 0; static uint32_t g_is_64_bit_capable = 0; static bool g_promoted_to_64 = false; - + if (g_host_cputype == 0) { g_promoted_to_64 = false; @@ -4571,7 +4571,7 @@ } } } - + len = sizeof(uint32_t); if (::sysctlbyname("hw.cpusubtype", &g_host_cpusubtype, &len, NULL, 0) == 0) { @@ -4580,7 +4580,7 @@ g_host_cpusubtype = CPU_SUBTYPE_X86_64_ALL; } } - + cputype = g_host_cputype; cpusubtype = g_host_cpusubtype; is_64_bit_capable = g_is_64_bit_capable; @@ -4891,15 +4891,15 @@ { std::ostringstream s; s << g_target_xml_header << std::endl; - + // Set the architecture //s << "" << arch "" << std::endl; - + // Set the OSABI //s << "abi-name" GenerateTargetXMLRegisters(s); - + s << g_target_xml_footer << std::endl; // Save the XML output in case it gets retrieved in chunks @@ -5004,7 +5004,7 @@ RNBRemote::HandlePacket_qGDBServerVersion (const char *p) { std::ostringstream strm; - + #if defined(DEBUGSERVER_PROGRAM_NAME) strm << "name:" DEBUGSERVER_PROGRAM_NAME ";"; #else @@ -5261,8 +5261,8 @@ nub_addr_t pthread_t_value = DNBGetPThreadT (pid, tid); uint64_t tsd_address = INVALID_NUB_ADDRESS; - if (plo_pthread_tsd_entry_size != INVALID_NUB_ADDRESS - && plo_pthread_tsd_base_offset != INVALID_NUB_ADDRESS + if (plo_pthread_tsd_entry_size != INVALID_NUB_ADDRESS + && plo_pthread_tsd_base_offset != INVALID_NUB_ADDRESS && plo_pthread_tsd_entry_size != INVALID_NUB_ADDRESS) { tsd_address = DNBGetTSDAddressForThread (pid, tid, plo_pthread_tsd_base_address_offset, plo_pthread_tsd_base_offset, plo_pthread_tsd_entry_size); @@ -5274,7 +5274,7 @@ // If the pthread_t value is invalid, or if we were able to fetch the thread's TSD base // and got an invalid value back, then we have a thread in early startup or shutdown and // it's possible that gathering the genealogy information for this thread go badly. - // Ideally fetching this info for a thread in these odd states shouldn't matter - but + // Ideally fetching this info for a thread in these odd states shouldn't matter - but // we've seen some problems with these new SPI and threads in edge-casey states. double genealogy_fetch_time = 0; @@ -5285,7 +5285,7 @@ genealogy_fetch_time = timer.ElapsedMicroSeconds(false) / 1000000.0; } - std::unordered_set process_info_indexes; // an array of the process info #'s seen + std::unordered_set process_info_indexes; // an array of the process info #'s seen json << "{"; @@ -5615,7 +5615,7 @@ rep << "effective-gid:" << std::hex << proc_kinfo.kp_eproc.e_ucred.cr_groups[0] << ";"; } } - + cpu_type_t cputype = DNBProcessGetCPUType (pid); if (cputype == 0) { @@ -5673,7 +5673,7 @@ // Check for iOS simulator binaries by getting the process argument // and environment and checking for SIMULATOR_UDID in the environment int proc_args_mib[3] = { CTL_KERN, KERN_PROCARGS2, (int)pid }; - + uint8_t arg_data[8192]; size_t arg_data_size = sizeof(arg_data); if (::sysctl (proc_args_mib, 3, arg_data, &arg_data_size , NULL, 0) == 0) @@ -5682,7 +5682,7 @@ DNBDataRef::offset_t offset = 0; uint32_t argc = data.Get32 (&offset); const char *cstr; - + cstr = data.GetCStr (&offset); if (cstr) { @@ -5699,7 +5699,7 @@ { data.GetCStr(&offset); } - + // Now iterate across all environment variables while ((cstr = data.GetCStr(&offset))) { @@ -5710,7 +5710,7 @@ } if (cstr[0] == '\0') break; - + } } } Index: tools/debugserver/source/debugserver.cpp =================================================================== --- tools/debugserver/source/debugserver.cpp +++ tools/debugserver/source/debugserver.cpp @@ -313,7 +313,6 @@ switch (pid_state) { - default: case eStateInvalid: case eStateUnloaded: case eStateAttaching: @@ -631,13 +630,13 @@ while (mode == eRNBRunLoopModePlatformMode) { std::string set_events_str; - const uint32_t event_mask = RNBContext::event_read_packet_available | + const uint32_t event_mask = RNBContext::event_read_packet_available | RNBContext::event_read_thread_exiting; - + DNBLogThreadedIf (LOG_RNB_EVENTS, "%s ctx.Events().WaitForSetEvents(0x%08x) ...",__FUNCTION__, event_mask); nub_event_t set_events = ctx.Events().WaitForSetEvents(event_mask); DNBLogThreadedIf (LOG_RNB_EVENTS, "%s ctx.Events().WaitForSetEvents(0x%08x) => 0x%08x (%s)",__FUNCTION__, event_mask, set_events, ctx.EventsAsString(set_events, set_events_str)); - + if (set_events) { if (set_events & RNBContext::event_read_packet_available) @@ -645,14 +644,14 @@ if (remote->HandleReceivedPacket() == rnb_not_connected) mode = eRNBRunLoopModeExit; } - + if (set_events & RNBContext::event_read_thread_exiting) { mode = eRNBRunLoopModeExit; } ctx.Events().ResetEvents(set_events); } - } + } return eRNBRunLoopModeExit; } @@ -665,9 +664,9 @@ PortWasBoundCallbackUnixSocket (const void *baton, in_port_t port) { //::printf ("PortWasBoundCallbackUnixSocket (baton = %p, port = %u)\n", baton, port); - + const char *unix_socket_name = (const char *)baton; - + if (unix_socket_name && unix_socket_name[0]) { // We were given a unix socket name to use to communicate the port @@ -679,37 +678,37 @@ perror("error: socket (AF_UNIX, SOCK_STREAM, 0)"); exit(1); } - + saddr_un.sun_family = AF_UNIX; ::strncpy(saddr_un.sun_path, unix_socket_name, sizeof(saddr_un.sun_path) - 1); saddr_un.sun_path[sizeof(saddr_un.sun_path) - 1] = '\0'; saddr_un.sun_len = SUN_LEN (&saddr_un); - + if (::connect (s, (struct sockaddr *)&saddr_un, static_cast(SUN_LEN (&saddr_un))) < 0) { perror("error: connect (socket, &saddr_un, saddr_un_len)"); exit(1); } - + //::printf ("connect () sucess!!\n"); - - + + // We were able to connect to the socket, now write our PID so whomever // launched us will know this process's ID RNBLogSTDOUT ("Listening to port %i...\n", port); - + char pid_str[64]; const int pid_str_len = ::snprintf (pid_str, sizeof(pid_str), "%u", port); const ssize_t bytes_sent = ::send (s, pid_str, pid_str_len, 0); - + if (pid_str_len != bytes_sent) { perror("error: send (s, pid_str, pid_str_len, 0)"); exit (1); } - + //::printf ("send () sucess!!\n"); - + // We are done with the socket close (s); } @@ -887,7 +886,7 @@ #if defined (__arm__) || defined (__arm64__) || defined (__aarch64__) struct sched_param thread_param; int thread_sched_policy; - if (pthread_getschedparam(pthread_self(), &thread_sched_policy, &thread_param) == 0) + if (pthread_getschedparam(pthread_self(), &thread_sched_policy, &thread_param) == 0) { thread_param.sched_priority = 47; pthread_setschedparam(pthread_self(), thread_sched_policy, &thread_param); @@ -909,25 +908,25 @@ // signal (SIGINT, signal_handler); signal (SIGPIPE, signal_handler); signal (SIGHUP, signal_handler); - + // We're always sitting in waitpid or kevent waiting on our target process' death, // we don't need no stinking SIGCHLD's... - + sigset_t sigset; sigemptyset(&sigset); sigaddset(&sigset, SIGCHLD); sigprocmask(SIG_BLOCK, &sigset, NULL); g_remoteSP.reset (new RNBRemote ()); - - + + RNBRemote *remote = g_remoteSP.get(); if (remote == NULL) { RNBLogSTDERR ("error: failed to create a remote connection class\n"); return -1; } - + RNBContext& ctx = remote->Context(); int i; @@ -959,11 +958,11 @@ char short_options[512]; uint32_t short_options_idx = 0; - + // Handle the two case that don't have short options in g_long_options short_options[short_options_idx++] = 'k'; short_options[short_options_idx++] = 't'; - + for (i=0; g_long_options[i].name != NULL; ++i) { if (isalpha(g_long_options[i].val)) @@ -972,7 +971,7 @@ switch (g_long_options[i].has_arg) { default: - case no_argument: + case no_argument: break; case optional_argument: @@ -986,7 +985,7 @@ } // NULL terminate the short option string. short_options[short_options_idx++] = '\0'; - + #if __GLIBC__ optind = 0; #else @@ -1068,7 +1067,7 @@ } } break; - + case 'K': g_detach_on_error = false; @@ -1126,7 +1125,7 @@ if (log_file != NULL) setlinebuf(log_file); } - + if (log_file == NULL) { const char *errno_str = strerror(errno); @@ -1177,7 +1176,7 @@ case 'O': ctx.GetSTDOUT().assign(optarg); break; - + case 'E': ctx.GetSTDERR().assign(optarg); break; @@ -1185,7 +1184,7 @@ case 'n': no_stdio = true; break; - + case 'S': // Put debugserver into a new session. Terminals group processes // into sessions and when a special terminal key sequences @@ -1203,7 +1202,7 @@ case 'D': g_disable_aslr = 1; break; - + case 'p': start_mode = eRNBRunLoopModePlatformMode; break; @@ -1215,12 +1214,12 @@ case 'P': named_pipe_path.assign (optarg); break; - + case 'e': // Pass a single specified environment variable down to the process that gets launched remote->Context().PushEnvironment(optarg); break; - + case 'F': // Pass the current environment down to the process that gets launched { @@ -1233,10 +1232,10 @@ break; } } - + if (arch_name.empty()) { -#if defined (__arm__) +#if defined (__arm__) arch_name.assign ("arm"); #endif } @@ -1265,7 +1264,7 @@ } remote->Context().SetDetachOnError(g_detach_on_error); - + remote->Initialize(); // It is ok for us to set NULL as the logfile (this will disable any logging) @@ -1584,7 +1583,7 @@ case eRNBRunLoopModeInferiorLaunching: { - mode = RNBRunLoopLaunchInferior (remote, + mode = RNBRunLoopLaunchInferior (remote, ctx.GetSTDINPath(), ctx.GetSTDOUTPath(), ctx.GetSTDERRPath(), @@ -1634,7 +1633,7 @@ if (remote->Comm().OpenFile (str)) mode = eRNBRunLoopModeExit; } - + if (mode != eRNBRunLoopModeExit) mode = RNBRunLoopPlatform (remote); break;