diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -4341,8 +4341,19 @@ // gdb_type could reference some flags type defined in XML. llvm::StringMap>::iterator it = registers_flags_types.find(gdb_type); - if (it != registers_flags_types.end()) - reg_info.flags_type = it->second.get(); + if (it != registers_flags_types.end()) { + auto flags_type = it->second.get(); + if (reg_info.byte_size == flags_type->GetSize()) + reg_info.flags_type = flags_type; + else + LLDB_LOGF(log, + "ProcessGDBRemote::ParseRegisters Size of register " + "flags %s (%d bytes) for " + "register %s does not match the register size (%d " + "bytes). Ignoring this set of flags.", + flags_type->GetID().c_str(), flags_type->GetSize(), + reg_info.name.AsCString(), reg_info.byte_size); + } // There's a slim chance that the gdb_type name is both a flags type // and a simple type. Just in case, look for that too (setting both diff --git a/lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py b/lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py --- a/lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py +++ b/lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py @@ -319,6 +319,20 @@ self.expect("register read cpsr", substrs=["(C = 1)"]) + @skipIfXmlSupportMissing + @skipIfRemote + def test_flags_register_size_mismatch(self): + # If the size of the flag set found does not match the size of the + # register, we discard the flags. + self.setup_register_test("""\ + + + + + """) + + self.expect("register read cpsr", substrs=["(C = 1)"], matching=False) + @skipIfXmlSupportMissing @skipIfRemote def test_flags_set_even_if_format_set(self): @@ -439,7 +453,7 @@ 'core.xml' : dedent("""\ - + @@ -475,23 +489,23 @@ 'core.xml' : dedent("""\ - + """), - # The my_flags here is ignored, so cpsr will use the my_flags from above. + # The my_flags here is ignored, so x1 will use the my_flags from above. 'core-2.xml' : dedent("""\ - + - + """), }) self.expect("register read x0", substrs=["(correct = 1)"]) - self.expect("register read cpsr", substrs=["(correct = 1)"]) + self.expect("register read x1", substrs=["(correct = 1)"])