Пример #1
0
void
LLDBGetAssembly::HandleSuccess
	(
	const JString& cmdData
	)
{
	LLDBLink* link = dynamic_cast<LLDBLink*>(CMGetLink());
	if (link == NULL)
		{
		return;
		}

	lldb::SBCommandInterpreter interp = link->GetDebugger()->GetCommandInterpreter();
	if (!interp.IsValid())
		{
		return;
		}

	const CMLocation& loc = (GetDirector())->GetDisassemblyLocation();

	const JString cmd = "disassemble -n " + JPrepArgForExec(loc.GetFunctionName());
	lldb::SBCommandReturnObject result;
	interp.HandleCommand(cmd, result);

	JPtrArray<JString> addrList(JPtrArrayT::kDeleteAll);
	JString instText;

	if (result.IsValid() && result.Succeeded() && result.HasResult())
		{
		std::istringstream input(result.GetOutput());
		JString line, s;
		JSize maxOffsetLength = 0;
		while (!input.eof() && !input.fail())
			{
			line = JReadLine(input);

			JIndex i;
			if (line.LocateSubstring(":", &i) && i < line.GetLength())
				{
				s = line.GetSubstring(1, i-1);
				if (s.BeginsWith("->") && s.GetLength() > 2)
					{
					s = s.GetSubstring(3, s.GetLength());
					}
				s.TrimWhitespace();
				addrList.Append(s);

				JIndexRange r;
				if (offsetPattern.Match(s, &r))
					{
					maxOffsetLength = JMax(maxOffsetLength, r.GetLength());
					}

				if (!instText.IsEmpty())
					{
					instText.AppendCharacter('\n');
					}
				s = line.GetSubstring(i+1, line.GetLength());
				s.TrimWhitespace();
				instText.Append(s);
				}
			}

		const JSize count = addrList.GetElementCount();
		for (JIndex i=1; i<count; i++)
			{
			JString* s = addrList.NthElement(i);
			JIndexRange r;
			if (offsetPattern.Match(*s, &r))
				{
				const JSize pad = maxOffsetLength - r.GetLength();
				for (JIndex j=0; j<pad; j++)
					{
					s->InsertCharacter('0', r.first+2);
					}
				}
			}
		}

	(GetDirector())->DisplayDisassembly(&addrList, instText);
}
Пример #2
0
int InteractivelyCollectAddresses(const wxArrayString& addresses,
                                  const String& bookNameOrig,
                                  const String& groupNameOrig,
                                  wxFrame *parent)
{
    // by default, select all addresses
    wxArrayInt selections;
    size_t count = addresses.GetCount();
    for ( size_t n = 0; n < count; n++ )
    {
       selections.Add(n);
    }

    if ( count > 1 )
    {
       // now ask the user which ones does he really want
       count = MDialog_GetSelections
                      (
                       _("Please select the addresses to save"),
                       _("Save addresses"),
                       addresses,
                       &selections,
                       parent,
                       _T("AddrExtract")
                      );
    }
    //else: don't ask the user to choose when there is one address only

    if ( count > 0 )
    {
       // ask the user for the book and group names to use
       //
       // TODO propose something better - ADB tree dialog for example
       wxString bookName(bookNameOrig),
                groupName(groupNameOrig);
       if ( MDialog_GetText2FromUser
            (
               _("Please select the location in the address\n"
                 "book to save the selected entries to:"),
               _("Save addresses"),
               _("Address book name:"), &bookName,
               _("Group name:"), &groupName,
               parent
            ) )
       {
         AdbManager_obj manager;
         CHECK( manager, -1, _T("can't get AdbManager") );

         AdbBook_obj autocollectbook(manager->CreateBook(bookName));

         if ( !autocollectbook )
         {
            wxLogError(_("Failed to create the address book '%s' "
                         "for autocollected e-mail addresses."),
                         bookName.c_str());

            // TODO ask the user for another book name
            return -1;
         }

         AdbEntryGroup_obj group(autocollectbook->CreateGroup(groupName));
         if ( !group )
         {
            wxLogError(_("Failed to create group '%s' in the address "
                         "book '%s'."),
                         groupName.c_str(), bookName.c_str());

            return -1;
         }

         // create all entries in this group
         size_t saved = 0;
         for ( size_t n = 0; n < count; n++ )
         {
            AddressList_obj addrList(addresses[selections[n]]);

            for ( Address *addr = addrList->GetFirst();
                  addr;
                  addr = addrList->GetNext(addr) )
            {
               String name = addr->GetName(),
                      email = addr->GetEMail();

               if ( name.empty() || name == email )
               {
                  name = addr->GetMailbox();
               }

               AdbEntry_obj entry(group->CreateEntry(name));
               entry->SetField(AdbField_NickName, name);
               entry->SetField(AdbField_FullName, name);
               entry->SetField(AdbField_EMail, email);

               saved++;
            }
         }

         wxLogStatus(parent, _("Saved %u addresses."), saved);
       }
       //else: cancelled
    }
    else // cancelled by user or nothing selected
    {
       wxLogStatus(parent, _("No addresses to save."));
    }

    return count;
}