Esempio n. 1
0
JString
XDLink::Build1DArrayExpression
	(
	const JCharacter*	origExpr,
	const JInteger		index
	)
{
	JString expr = origExpr;

	const JString indexStr(index, 0);	// must use floating point conversion
	if (expr.Contains("$i"))
		{
		// double literal $'s

		for (JIndex i=expr.GetLength()-1; i>=1; i--)
			{
			if (expr.GetCharacter(i)   == '$' &&
				expr.GetCharacter(i+1) != 'i')
				{
				expr.InsertCharacter('$', i);
				}
			}

		const JCharacter* map[] =
			{
			"i", indexStr.GetCString()
			};
		(JGetStringManager())->Replace(&expr, map, sizeof(map));
		}
	else
		{
		expr.AppendCharacter('[');
		expr += indexStr;
		expr.AppendCharacter(']');
		}

	return expr;
}
Esempio n. 2
0
JString
XDLink::Build2DArrayExpression
	(
	const JCharacter*	origExpr,
	const JInteger		rowIndex,
	const JInteger		colIndex
	)
{
	JString expr = origExpr;

	const JBoolean usesI = expr.Contains("$i");		// row
	const JBoolean usesJ = expr.Contains("$j");		// col

	const JString iStr(rowIndex, 0);	// must use floating point conversion
	const JString jStr(colIndex, 0);	// must use floating point conversion

	// We have to do both at the same time because otherwise we lose a $.

	if (usesI || usesJ)
		{
		// double literal $'s

		for (JIndex i=expr.GetLength()-1; i>=1; i--)
			{
			if (expr.GetCharacter(i)   == '$' &&
				expr.GetCharacter(i+1) != 'i' &&
				expr.GetCharacter(i+1) != 'j')
				{
				expr.InsertCharacter('$', i);
				}
			}

		const JCharacter* map[] =
			{
			"i", iStr.GetCString(),
			"j", jStr.GetCString()
			};
		(JGetStringManager())->Replace(&expr, map, sizeof(map));
		}

	if (!usesI || !usesJ)
		{
		if (expr.GetFirstCharacter() != '(' ||
			expr.GetLastCharacter()  != ')')
			{
			expr.PrependCharacter('(');
			expr.AppendCharacter(')');
			}

		if (!usesI)
			{
			expr.AppendCharacter('[');
			expr += iStr;
			expr.AppendCharacter(']');
			}
		if (!usesJ)
			{
			expr.AppendCharacter('[');
			expr += jStr;
			expr.AppendCharacter(']');
			}
		}

	return expr;
}
Esempio n. 3
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);
}