Instruction getting resized

Hi,

I am trying to read an instruction in a phase built on the MIR output. However this instruction is getting resized and only a part of it is being given to me when I do a writeline on the Instruction. Is there any way to maintain the true size and contents of my instruction.

Thanks,

Arjun

[324 byte] By [ArjunDasgupta] at [2008-2-24]
# 1
Arjun, can you show the output you see and the output you expect to see? I'm not quite sure what you mean when you write "this instruction is getting resized".
AndyAyers-MSFT at 2007-10-2 > top of Msdn Tech,Visual Studio,Phoenix...
# 2

Here goes....

say there is an instruction in a .cpp file to which I add my phoenix phase during compilation:

Code Snippet
SqlConnection * mySqlConnection =
new SqlConnection("server=localhost;Trusted_Connection=yes;database=northwind;provider=sqloledb");

This gets translated to something like the below when I do a writeline on the instructions in the MIR phase:

<<--

t283, {*CallTag} = NEWOBJ* &?0String@System@@$$FQ$AAM@PBD@Z, &?_C@_0EN@LKCDADA@server?$DNlocalhost?$DLTrusted_Connect@, {*CallTag}, $L5(EH)

->>

The thing to notice above is that the connection string that I have used is not present in its entirety. I am trying to get this whole connection string to be reflected when I read or write the instruction in the MIR Phase.

ANOTHER QUESTION: Is there any way to translate and remove the extra characters inserted in a string during the MIR phase? As in the previous question, can we get server?$DNlocalhost?$DLTrusted_Connect.... in its original form?

Thanks in advance,

Arjun Dasgupta

ArjunDasgupta at 2007-10-2 > top of Msdn Tech,Visual Studio,Phoenix...
# 3

I have a code sample that works for compiling C/C++, but here it looks like you are compiling MC++ code, and getting from the symbol representing the string to the string value in MC++ compiles is somewhat more complicated, and I don't have a ready answer for you.

It turns out that the front-end creates a symbol for the string's value that is related to the string itself (though truncated, as you noticed). This doesn't really help you any if your goal is to recover the string.

AndyAyers-MSFT at 2007-10-2 > top of Msdn Tech,Visual Studio,Phoenix...
# 4
Hi Andy,

Thanks a lot for your feedback. Will it be possible to post a snippet of the C/C++ string that does this. It would be great if I have that.
Also, is it possible to somehow parse the original string from the compiler specific string + characters without using something like a regex function? Is there some kind of API in the Phoenix infrastructure that allows something like this?

Thanking you,

ArjunDasgupta at 2007-10-2 > top of Msdn Tech,Visual Studio,Phoenix...
# 5

Here's some code that works for regular string literals and for MC++ literals without the 'S' prefix:

Code Snippet

unsafe static string GetStringFromOperand(Phx.IR.Operand operand)

{

// Only variable operands with non local variable symbols will represent initialized strings.

if (!operand.IsVariableOperand)

{

return null;

}

Phx.Symbols.Symbol symbol = operand.Symbol;

if (symbol == null || !symbol.IsNonLocalVariableSymbol)

{

return null;

}

Phx.Symbols.GlobalVariableSymbol globalSymbol = symbol.AsNonLocalVariableSymbol.GlobalSymbol;

if (globalSymbol.Location == null)

{

return null;

}

Phx.IR.DataInstruction dataInstruction = globalSymbol.Location.AsDataLocation.DataInstruction;

// Now see if we have an initialized string, or a pointer to an initialized string. The latter

// will be represented via a fixup.

Phx.Targets.Architectures.Fixup fixupList = dataInstruction.FixupList;

if (fixupList != null)

{

if (fixupList.TargetSymbol != null)

{

Phx.Symbols.Symbol fixupSymbol = fixupList.TargetSymbol;

if (fixupSymbol.Location != null && fixupSymbol.Location.IsDataLocation)

{

Phx.IR.DataInstruction fixupInstruction = dataInstruction.FixupList.TargetSymbol.Location.AsDataLocation.DataInstruction;

return Phx.Utility.Utf8Decode(fixupInstruction.GetDataPointer(0), (int)fixupInstruction.ByteSize);

}

}

}

else

{

return Phx.Utility.Utf8Decode(dataInstruction.GetDataPointer(0), (int)dataInstruction.ByteSize);

}

return null;

}

For instance, if I create a plugin that calls this method on each source operand in the IR, and compile the following with -clr: oldSyntax:

Code Snippet

int f(System::String * s)
{

if (s->Equals(S"Phx.Plugin"))
return 0;
return 1;

}

void main()
{
System::String * s = "Phx.Plugin";
if (f(s))
{ System::Console::WriteLine("ok"); }
else
{ System::Console::WriteLine("bad"); }
}

I get the following output:

Code Snippet
String for &$SG5691 is Phx.Plugin
String for &$SG6696 is ok
String for &$SG6698 is bad

The three regular string literals show up, but the literal for S"Phx.Plugin" is encoded as a string in metadata and the code snippet here is unable to find its value.

AndyAyers-MSFT at 2007-10-2 > top of Msdn Tech,Visual Studio,Phoenix...
# 6

Thanks a lot Andy!

ArjunDasgupta at 2007-10-2 > top of Msdn Tech,Visual Studio,Phoenix...

Visual Studio

Site Classified