Author: jmolenda Date: Fri Apr 17 14:15:02 2015 New Revision: 235218 URL: http://llvm.org/viewvc/llvm-project?rev=235218&view=rev Log: Whitespace-only tweaks to Colin's r235109 patch to match the lldb coding style a little more closely.
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=235218&r1=235217&r2=235218&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Fri Apr 17 14:15:02 2015 @@ -3442,9 +3442,11 @@ namespace { typedef std::vector<std::string> stringVec; typedef std::vector<xmlNodePtr> xmlNodePtrVec; -struct GdbServerRegisterInfo { +struct GdbServerRegisterInfo +{ - struct { + struct + { bool m_has_name : 1; bool m_has_bitSize : 1; bool m_has_type : 1; @@ -3458,7 +3460,8 @@ struct GdbServerRegisterInfo { uint32_t m_bitSize; uint32_t m_regNum; - enum RegType { + enum RegType + { eUnknown , eCodePtr , eDataPtr , @@ -3467,25 +3470,28 @@ struct GdbServerRegisterInfo { } m_type; - void clear( ) { - memset( &m_flags, 0, sizeof( m_flags ) ); + void clear() + { + memset(&m_flags, 0, sizeof(m_flags)); } }; typedef std::vector<struct GdbServerRegisterInfo> GDBServerRegisterVec; -struct GdbServerTargetInfo { - +struct GdbServerTargetInfo +{ std::string m_arch; std::string m_osabi; }; // conversion table between gdb register type and enum -struct { +struct +{ const char * m_name; GdbServerRegisterInfo::RegType m_type; } -RegTypeTable[] = { +RegTypeTable[] = +{ { "int32" , GdbServerRegisterInfo::eInt32 }, { "int" , GdbServerRegisterInfo::eInt32 }, { "data_ptr", GdbServerRegisterInfo::eDataPtr }, @@ -3497,7 +3503,8 @@ RegTypeTable[] = { // find the first sibling with a matching name xmlNodePtr xmlExFindSibling (xmlNodePtr node, - const std::string & name) { + const std::string & name) +{ if ( !node ) return nullptr; // iterate through all siblings @@ -3517,19 +3524,22 @@ xmlExFindSibling (xmlNodePtr node, // find an element from a given element path xmlNodePtr xmlExFindElement (xmlNodePtr node, - const stringVec & path) { + const stringVec & path) +{ - if ( !node ) return nullptr; + if (!node) + return nullptr; xmlNodePtr temp = node; // iterate all elements in path - for ( uint32_t i = 0; i < path.size( ); i++ ) { + for (uint32_t i = 0; i < path.size(); i++) + { // search for a sibling with this name - temp = xmlExFindSibling( temp, path[i] ); - if ( !temp ) + temp = xmlExFindSibling(temp, path[i]); + if (!temp) return nullptr; // enter this node if we still need to search - if ( (i+1) < path.size() ) + if ((i + 1) < path.size()) // enter the node we have found temp = temp->children; } @@ -3539,18 +3549,21 @@ xmlExFindElement (xmlNodePtr node, // locate a specific attribute in an element xmlAttr * -xmlExFindAttribute (xmlNodePtr node, - const std::string & name) { +xmlExFindAttribute (xmlNodePtr node, + const std::string & name) +{ - if ( !node ) + if (!node) return nullptr; - if ( node->type != XML_ELEMENT_NODE ) + if (node->type != XML_ELEMENT_NODE) return nullptr; // iterate over all attributes - for ( xmlAttrPtr attr = node->properties; attr != nullptr; attr=attr->next ) { + for (xmlAttrPtr attr = node->properties; attr != nullptr; attr=attr->next) + { // check if name matches - if ( !attr->name ) continue; - if ( std::strcmp( (const char*)attr->name, name.c_str( ) ) == 0 ) + if (!attr->name) + continue; + if (std::strcmp((const char*) attr->name, name.c_str()) == 0) return attr; } return nullptr; @@ -3563,19 +3576,24 @@ xmlExFindAttribute (xmlNodePtr node, // output: out = list of matches // return: number of children added to 'out' int -xmlExFindChildren (xmlNodePtr node, - const std::string & name, - xmlNodePtrVec & out) { +xmlExFindChildren (xmlNodePtr node, + const std::string & name, + xmlNodePtrVec & out) +{ - if ( !node ) return 0; + if (!node) + return 0; int count = 0; // iterate over all children - for ( xmlNodePtr child = node->children; child; child = child->next ) { + for (xmlNodePtr child = node->children; child; child = child->next) + { // if name matches - if ( !child->name ) continue; - if ( std::strcmp( (const char*)child->name, name.c_str( ) ) == 0 ) { + if (!child->name) + continue; + if (std::strcmp((const char*) child->name, name.c_str()) == 0) + { // add to output list - out.push_back( child ); + out.push_back(child); ++count; } } @@ -3584,36 +3602,36 @@ xmlExFindChildren (xmlNodePtr node, // get the text content from an attribute std::string -xmlExGetTextContent (xmlAttrPtr attr) { - - if ( !attr ) - return std::string( ); - if ( attr->type != XML_ATTRIBUTE_NODE ) - return std::string( ); +xmlExGetTextContent (xmlAttrPtr attr) +{ + if (!attr) + return std::string(); + if (attr->type != XML_ATTRIBUTE_NODE) + return std::string(); // check child is a text node xmlNodePtr child = attr->children; - if ( child->type != XML_TEXT_NODE ) - return std::string( ); + if (child->type != XML_TEXT_NODE) + return std::string(); // access the content - assert( child->content != nullptr ); - return std::string( (const char*) child->content ); + assert(child->content != nullptr); + return std::string((const char*) child->content); } // get the text content from an node std::string -xmlExGetTextContent (xmlNodePtr node) { - - if ( !node ) - return std::string( ); - if ( node->type != XML_ELEMENT_NODE ) - return std::string( ); +xmlExGetTextContent (xmlNodePtr node) +{ + if (!node) + return std::string(); + if (node->type != XML_ELEMENT_NODE) + return std::string(); // check child is a text node xmlNodePtr child = node->children; - if ( child->type != XML_TEXT_NODE ) - return std::string( ); + if (child->type != XML_TEXT_NODE) + return std::string(); // access the content - assert( child->content != nullptr ); - return std::string( (const char*) child->content ); + assert(child->content != nullptr); + return std::string((const char*) child->content); } // compile a list of xml includes from the target file @@ -3621,20 +3639,24 @@ xmlExGetTextContent (xmlNodePtr node) { // output: includes = list of .xml names specified in target.xml // return: number of .xml files specified in target.xml and added to includes int -parseTargetIncludes (xmlDocPtr doc, stringVec & includes) { - - if ( !doc ) return 0; +parseTargetIncludes (xmlDocPtr doc, stringVec & includes) +{ + if (!doc) + return 0; int count = 0; - xmlNodePtr elm = xmlExFindElement( doc->children, { "target" } ); - if (! elm ) return 0; + xmlNodePtr elm = xmlExFindElement(doc->children, {"target"}); + if (!elm) + return 0; xmlNodePtrVec nodes; - xmlExFindChildren( elm, "xi:include", nodes ); + xmlExFindChildren(elm, "xi:include", nodes); // iterate over all includes - for ( uint32_t i = 0; i < nodes.size(); i++ ) { - xmlAttrPtr attr = xmlExFindAttribute( nodes[i], "href" ); - if ( attr != nullptr ) { - std::string text = xmlExGetTextContent( attr ); - includes.push_back( text ); + for (uint32_t i = 0; i < nodes.size(); i++) + { + xmlAttrPtr attr = xmlExFindAttribute(nodes[i], "href"); + if (attr != nullptr) + { + std::string text = xmlExGetTextContent(attr); + includes.push_back(text); ++count; } } @@ -3647,16 +3669,19 @@ parseTargetIncludes (xmlDocPtr doc, stri // return: 'true' on success // 'false' on failure bool -parseTargetInfo (xmlDocPtr doc, GdbServerTargetInfo & out) { +parseTargetInfo (xmlDocPtr doc, GdbServerTargetInfo & out) +{ + if (!doc) + return false; + xmlNodePtr e1 = xmlExFindElement (doc->children, {"target", "architecture"}); + if (!e1) + return false; + out.m_arch = xmlExGetTextContent (e1); - if ( !doc ) return false; - xmlNodePtr e1 = xmlExFindElement( doc->children, { "target", "architecture" } ); - if ( !e1 ) return false; - out.m_arch = xmlExGetTextContent( e1 ); - - xmlNodePtr e2 = xmlExFindElement( doc->children, { "target", "osabi" } ); - if ( !e2 ) return false; - out.m_osabi = xmlExGetTextContent( e2 ); + xmlNodePtr e2 = xmlExFindElement (doc->children, {"target", "osabi"}); + if (!e2) + return false; + out.m_osabi = xmlExGetTextContent (e2); return true; } @@ -3667,39 +3692,48 @@ parseTargetInfo (xmlDocPtr doc, GdbServe // return: 'true' on success // 'false' on failure bool -parseRegisters (xmlDocPtr doc, GDBServerRegisterVec & regList) { +parseRegisters (xmlDocPtr doc, GDBServerRegisterVec & regList) +{ - if ( !doc ) return false; - xmlNodePtr elm = xmlExFindElement( doc->children, { "feature" } ); - if ( !elm ) return false; + if (!doc) + return false; + xmlNodePtr elm = xmlExFindElement (doc->children, {"feature"}); + if (!elm) + return false; xmlAttrPtr attr = nullptr; xmlNodePtrVec regs; - xmlExFindChildren( elm, "reg", regs ); - for ( unsigned long i = 0; i < regs.size( ); i++ ) { + xmlExFindChildren (elm, "reg", regs); + for (unsigned long i = 0; i < regs.size(); i++) + { GdbServerRegisterInfo reg; - reg.clear( ); + reg.clear(); - if ( ( attr = xmlExFindAttribute( regs[i], "name" ) ) ) { - reg.m_name = xmlExGetTextContent( attr ).c_str(); + if ((attr = xmlExFindAttribute(regs[i], "name"))) + { + reg.m_name = xmlExGetTextContent(attr).c_str(); reg.m_flags.m_has_name = true; } - if ( ( attr = xmlExFindAttribute( regs[i], "bitsize" ) ) ) { - const std::string v = xmlExGetTextContent( attr ); - reg.m_bitSize = atoi( v.c_str( ) ); + if ((attr = xmlExFindAttribute( regs[i], "bitsize"))) + { + const std::string v = xmlExGetTextContent(attr); + reg.m_bitSize = atoi(v.c_str()); reg.m_flags.m_has_bitSize = true; } - if ( ( attr = xmlExFindAttribute( regs[i], "type" ) ) ) { - const std::string v = xmlExGetTextContent( attr ); + if ((attr = xmlExFindAttribute(regs[i], "type"))) + { + const std::string v = xmlExGetTextContent(attr); reg.m_type = GdbServerRegisterInfo::eUnknown; // search the type table for a match - for ( int j = 0; RegTypeTable[j].m_name !=nullptr ;++j ) { - if (RegTypeTable[j].m_name == v) { + for (int j = 0; RegTypeTable[j].m_name !=nullptr; ++j) + { + if (RegTypeTable[j].m_name == v) + { reg.m_type = RegTypeTable[j].m_type; break; } @@ -3708,18 +3742,20 @@ parseRegisters (xmlDocPtr doc, GDBServer reg.m_flags.m_has_type = (reg.m_type != GdbServerRegisterInfo::eUnknown); } - if ( ( attr = xmlExFindAttribute( regs[i], "group" ) ) ) { - reg.m_group = xmlExGetTextContent( attr ); + if ((attr = xmlExFindAttribute( regs[i], "group"))) + { + reg.m_group = xmlExGetTextContent(attr); reg.m_flags.m_has_group = true; } - if ( ( attr = xmlExFindAttribute( regs[i], "regnum" ) ) ) { - const std::string v = xmlExGetTextContent( attr ); - reg.m_regNum = atoi( v.c_str( ) ); + if ((attr = xmlExFindAttribute(regs[i], "regnum"))) + { + const std::string v = xmlExGetTextContent(attr); + reg.m_regNum = atoi(v.c_str()); reg.m_flags.m_has_regNum = true; } - regList.push_back( reg ); + regList.push_back(reg); } //TODO: there is also a "vector" element to parse @@ -3733,7 +3769,8 @@ parseRegisters (xmlDocPtr doc, GDBServer // output: regInfo = dynamic register information required by gdb-remote void BuildRegisters (const GDBServerRegisterVec & regList, - GDBRemoteDynamicRegisterInfo & regInfo) { + GDBRemoteDynamicRegisterInfo & regInfo) +{ using namespace lldb_private; @@ -3741,7 +3778,8 @@ BuildRegisters (const GDBServerRegisterV uint32_t regNum = 0; uint32_t byteOffset = 0; - for ( uint32_t i = 0; i < regList.size( ); ++i ) { + for (uint32_t i = 0; i < regList.size(); ++i) + { const GdbServerRegisterInfo & gdbReg = regList[i]; @@ -3749,7 +3787,7 @@ BuildRegisters (const GDBServerRegisterV std::string group = gdbReg.m_flags.m_has_group ? gdbReg.m_group : "general"; uint32_t byteSize = gdbReg.m_flags.m_has_bitSize ? (gdbReg.m_bitSize/8) : defSize; - if ( gdbReg.m_flags.m_has_regNum ) + if (gdbReg.m_flags.m_has_regNum) regNum = gdbReg.m_regNum; uint32_t regNumGcc = LLDB_INVALID_REGNUM; @@ -3758,28 +3796,33 @@ BuildRegisters (const GDBServerRegisterV uint32_t regNumGdb = regNum; uint32_t regNumNative = regNum; - if ( name == "eip" || name == "pc" ) { + if (name == "eip" || name == "pc") + { regNumGeneric = LLDB_REGNUM_GENERIC_PC; } - if ( name == "esp" || name == "sp" ) { + if (name == "esp" || name == "sp") + { regNumGeneric = LLDB_REGNUM_GENERIC_SP; } - if ( name == "ebp") { + if (name == "ebp") + { regNumGeneric = LLDB_REGNUM_GENERIC_FP; } - if ( name == "lr" ) { + if (name == "lr") + { regNumGeneric = LLDB_REGNUM_GENERIC_RA; } - RegisterInfo info = { + RegisterInfo info = + { name.c_str(), nullptr , byteSize , byteOffset , lldb::Encoding::eEncodingUint, lldb::Format::eFormatDefault, - { regNumGcc , - regNumDwarf , + { regNumGcc , + regNumDwarf , regNumGeneric, regNumGdb , regNumNative }, @@ -3787,10 +3830,10 @@ BuildRegisters (const GDBServerRegisterV nullptr }; - ConstString regName = ConstString( gdbReg.m_name ); - ConstString regAltName = ConstString( ); - ConstString regGroup = ConstString( group ); - regInfo.AddRegister( info, regName, regAltName, regGroup ); + ConstString regName = ConstString(gdbReg.m_name); + ConstString regAltName = ConstString(); + ConstString regGroup = ConstString(group); + regInfo.AddRegister(info, regName, regAltName, regGroup); // advance register info byteOffset += byteSize; @@ -3829,54 +3872,58 @@ ProcessGDBRemote::GetGDBServerInfo () // request the target xml file std::string raw; lldb_private::Error lldberr; - if (! comm.ReadExtFeature( ConstString( "features" ), - ConstString( "target.xml" ), - raw, - lldberr ) ) { + if (!comm.ReadExtFeature(ConstString("features"), + ConstString("target.xml"), + raw, + lldberr)) + { return false; } // parse the xml file in memory - xmlDocPtr doc = xmlReadMemory( raw.c_str( ), raw.size( ), "noname.xml", nullptr, 0 ); - if ( doc == nullptr ) + xmlDocPtr doc = xmlReadMemory(raw.c_str(), raw.size(), "noname.xml", nullptr, 0); + if (doc == nullptr) return false; // extract target info from target.xml GdbServerTargetInfo gdbInfo; - if ( parseTargetInfo( doc, gdbInfo ) ) { + if (parseTargetInfo(doc, gdbInfo)) + { // NOTE: We could deduce triple from gdbInfo if lldb doesn't already have one set } // collect registers from all of the includes GDBServerRegisterVec regList; stringVec includes; - if ( parseTargetIncludes( doc, includes ) > 0 ) { + if (parseTargetIncludes(doc, includes) > 0) + { - for ( uint32_t i = 0; i < includes.size( ); ++i ) { + for (uint32_t i = 0; i < includes.size(); ++i) + { // request register file - if ( !comm.ReadExtFeature( ConstString( "features" ), - ConstString( includes[i] ), - raw, - lldberr ) ) + if (!comm.ReadExtFeature(ConstString("features"), + ConstString(includes[i]), + raw, + lldberr)) continue; // parse register file - xmlDocPtr regXml = xmlReadMemory( raw.c_str(), - raw.size( ), - includes[i].c_str(), - nullptr, - 0 ); - if ( !regXml ) + xmlDocPtr regXml = xmlReadMemory(raw.c_str(), + raw.size( ), + includes[i].c_str(), + nullptr, + 0); + if (!regXml) continue; // pass registers to lldb - parseRegisters( regXml, regList ); + parseRegisters(regXml, regList); } } // pass all of these registers to lldb - BuildRegisters( regList, regInfo ); + BuildRegisters(regList, regInfo); return true; } _______________________________________________ lldb-commits mailing list lldb-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits