예제 #1
0
        public ShowSrcDissStruct show_diss_common()
        {
            try
            {
                int startPrev = m_registerSet.GetPC();
                int endNext   = m_registerSet.GetPC();
                if (MainWindow.mIsAPUMode)
                {
                    startPrev -= 16;
                    endNext   += 16;
                }
                else
                {
                    // MPi: TODO: Tweak the 10 range based on the display height?
                    int range = 15;
                    // Step backwards trying to find a good starting point to disassemble
                    while (range-- > 0)
                    {
                        AddrInfo addrInfo2 = m_PDBData.getAddrInfoForAddr(startPrev); //mAddrInfoByAddr[startPrev];
                        if (addrInfo2.mPrevAddr < 0)
                        {
                            break;
                        }
                        startPrev = addrInfo2.mPrevAddr;
                    }

                    // MPi: TODO: Tweak the 10 range based on the display height?
                    range = 20;
                    // Step forwards trying to find a good ending point to disassemble
                    while (range-- > 0)
                    {
                        AddrInfo addrInfo2 = m_PDBData.getAddrInfoForAddr(endNext); //mAddrInfoByAddr[endNext];
                        if (addrInfo2.mNextAddr < 0)
                        {
                            break;
                        }
                        endNext = addrInfo2.mNextAddr;
                    }
                }

                ShowSrcDissStruct sms = new ShowSrcDissStruct()
                {
                    endNext = endNext
                    ,
                    startPrev = startPrev
                };
                return(sms);
            }
            catch (Exception)
            {
            }
            return(null);
        }
예제 #2
0
파일: PDBData.cs 프로젝트: martinpiper/ACME
 public AddrInfo getAddrInfoForAddr(int PC)
 {
     if (MainWindow.mIsAPUMode)
     {
         AddrInfo tweakedInfo = mAddrInfoByAddr[(PC * 4) + mAPUCode_Start];
         tweakedInfo.mAddr    -= mAPUCode_Start;
         tweakedInfo.mAddr    /= 4;
         tweakedInfo.mNextAddr = tweakedInfo.mAddr + 1;
         tweakedInfo.mPrevAddr = tweakedInfo.mAddr - 1;
         if (tweakedInfo.mPrevAddr < 0)
         {
             tweakedInfo.mPrevAddr = 0;
         }
         return(tweakedInfo);
     }
     return(mAddrInfoByAddr[PC]);
 }
예제 #3
0
        public string ShowSrcPostRegisters()
        {
            string displayText = string.Empty;

            try
            {
                AddrInfo addrInfo = m_PDBData.getAddrInfoForAddr(m_registerSet.GetPC()); // mAddrInfoByAddr[mPC];
                // MPi: TODO: Tweak the 20 range based on the display height?
                int range     = 20;
                int startPrev = m_registerSet.GetPC();
                // Step backwards trying to find a good starting point to disassemble
                while (range-- > 0)
                {
                    AddrInfo addrInfo2 = m_PDBData.getAddrInfoForAddr(startPrev); // mAddrInfoByAddr[startPrev];
                    if (addrInfo2.mPrevAddr < 0)
                    {
                        break;
                    }
                    startPrev = addrInfo2.mPrevAddr;
                }

                displayText += "File:" + m_PDBData.getSourceFileName(addrInfo.mFile) + "\n"; // mSourceFileNames[addrInfo.mFile] + "\n";
                displayText += "Line:" + (addrInfo.mLine + 1) + "\n";
                int theLine = addrInfo.mLine - 10;                                           // MPi: TODO: Tweak the - 10 based on the display height?
                if (theLine < 0)
                {
                    theLine = 0;
                }
                // MPi: TODO: Tweak the 20 toDisplay based on the display height?
                int toDisplay = 30;
                while (toDisplay-- > 0)
                {
                    if (theLine == addrInfo.mLine)
                    {
                        displayText += "=>";
                    }
                    else
                    {
                        displayText += "  ";
                    }
                    string source = m_PDBData.getLineFromSourceFile(addrInfo.mFile, theLine++);  //mSourceFiles[addrInfo.mFile][theLine++];
                    source = source.Replace('\n', '\r');
                    source.TrimEnd();

                    displayText += source;
                    displayText += "\r";
                }
            }
            catch (System.Exception)
            {
                /*SendCommand("m 0000 ffff");
                 * theReply = GetReply();
                 * // No source info, so just dump memory
                 * gotText += theReply;
                 * //>C:0000  2f 37 00 aa  b1 91 b3 22  00 00 00 4c  00 00 00 04   /7....."...L....
                 * //>C:0010  00 00 00 00  00 04 19 16  00 0a 76 a3  00 00 00 00   ..........v.....
                 * //...
                 * //>C:ff00  00 00 00 00  00 04 19 16  00 0a 76 a3  00 00 00 00   ..........v.....*/
            }
            return(displayText);
        }
예제 #4
0
        public string ShowSrcDissGetPostDissaem(string reply, object userData)
        {
            ShowSrcDissStruct sms = userData as ShowSrcDissStruct;

            sms.disassemblyAfter = reply;
            string displayText = String.Empty;

            try
            {
                string lastSourceDisplayed      = "";
                int    lastSourceIndexDisplayed = -1;
                int    lastSourceLineDisplayed  = -1;

                int[] lastDisplayedLine = new int[m_PDBData.getNumFiles()]; //mSourceFileNamesLength
                int   i;
                for (i = 0; i < m_PDBData.getNumFiles(); i++)               //mSourceFileNamesLength
                {
                    lastDisplayedLine[i] = 0;
                }

                //							gotText += disassemblyBefore;
                //							gotText += ">>>\n";
                //							gotText += disassemblyAfter;
                // Get something like:

                /*
                 *  .C:0427  AD 00 04    LDA $0400
                 *  .C:042a  AD 27 04    LDA $0427
                 *  ...
                 *  .C:0439  60          RTS
                 *  .C:043a  AD 3A 04    LDA $043A
                 */
                string[] split          = sms.disassemblyBefore.Split('\r');
                bool     doingBefore    = true;
                int      index          = 0;
                String   lastSourceLine = "";
                while (index < split.Length)
                {
                    string line = split[index++];
                    if (line.Length < 7)
                    {
                        continue;
                    }
                    if (!line.StartsWith(".C:"))
                    {
                        continue;
                    }
                    string tAddr = line.Substring(3);
                    tAddr = tAddr.Substring(0, 4);
                    int theAddr = int.Parse(tAddr, NumberStyles.HexNumber);
                    if (doingBefore && theAddr >= m_registerSet.GetPC())
                    {
                        split       = sms.disassemblyAfter.Split('\r');
                        index       = 0;
                        doingBefore = false;
                        continue;
                    }

                    try
                    {
                        AddrInfo addrInfo = m_PDBData.getAddrInfoForAddr(theAddr);              //mAddrInfoByAddr[theAddr];
                        if (lastSourceDisplayed != m_PDBData.getSourceFileName(addrInfo.mFile)) //mSourceFileNames[addrInfo.mFile])
                        {
                            lastSourceDisplayed = m_PDBData.getSourceFileName(addrInfo.mFile);  // mSourceFileNames[addrInfo.mFile];
                            displayText        += "--- " + lastSourceDisplayed + " ---\r";
                        }
                        if ((addrInfo.mLine - lastDisplayedLine[addrInfo.mFile]) > 5)
                        {
                            lastDisplayedLine[addrInfo.mFile] = addrInfo.mLine - 5;
                            if (lastDisplayedLine[addrInfo.mFile] < 0)
                            {
                                lastDisplayedLine[addrInfo.mFile] = 0;
                            }
                        }
                        if (lastDisplayedLine[addrInfo.mFile] > addrInfo.mLine)
                        {
                            lastDisplayedLine[addrInfo.mFile] = addrInfo.mLine;
                        }
                        for (i = lastDisplayedLine[addrInfo.mFile]; i <= addrInfo.mLine; i++)
                        {
                            if (lastSourceLine.Length > 0)
                            {
                                //gotText += "     " + "                                  " + lastSourceLine + "\n";
                                displayText   += "     " + lastSourceLine + "\r";
                                lastSourceLine = "";
                            }

                            if ((lastSourceIndexDisplayed == addrInfo.mFile) && (lastSourceLineDisplayed == i))
                            {
                                // Stop displaying the same source and line multiple times in a row
                                continue;
                            }
                            lastSourceLine           = string.Format("{0,5:###}", i) + ": " + m_PDBData.getLineFromSourceFile(addrInfo.mFile, i); // mSourceFiles[addrInfo.mFile][i];
                            lastSourceIndexDisplayed = addrInfo.mFile;
                            lastSourceLineDisplayed  = i;
                        }
                        lastDisplayedLine[addrInfo.mFile] = addrInfo.mLine + 1;
                    }
                    catch (System.Exception)
                    {
                    }

                    if (theAddr == m_registerSet.GetPC())
                    {
                        displayText += ">>>> ";
                    }
                    else
                    {
                        displayText += "     ";
                    }
                    if (lastSourceLine.Length > 0)
                    {
                        line           = line.PadRight(34, ' ');
                        displayText   += line + lastSourceLine + "\r";
                        lastSourceLine = "";
                    }
                    else
                    {
                        displayText += line + "\r";
                    }
                }
            }
            catch (System.Exception)
            {
            }

            return(displayText);
        }
예제 #5
0
파일: PDBData.cs 프로젝트: martinpiper/ACME
        public void parseData(string[] commandLineArgs)
        {
            int    i;
            string line;

            for (i = 1; i < commandLineArgs.Length; i++)
            {
                int localFileIndex = 0;

                // Read the file and parse it line by line.
                using (System.IO.StreamReader file = new System.IO.StreamReader(commandLineArgs[i]))
                {
                    while ((line = file.ReadLine()) != null)
                    {
                        if (line.IndexOf("INCLUDES:") == 0)
                        {
                            int lines = int.Parse(line.Substring(9));
                            mSourceIncludes.Clear();
                            mSourceIncludes.Add(".\\");
                            while (lines-- > 0)
                            {
                                line = file.ReadLine();
                                mSourceIncludes.Add(line);
                            }
                        }
                        else if (line.IndexOf("FILES:") == 0)
                        {
                            localFileIndex = mSourceFileNamesLength;
                            int lines = int.Parse(line.Substring(6));
                            mSourceFileNamesLength += lines;
                            if (mSourceFileNames != null)
                            {
                                // Copy old into new
                                string[] tempNames = new string[mSourceFileNamesLength];
                                int      j;
                                for (j = 0; j < localFileIndex; j++)
                                {
                                    tempNames[j] = mSourceFileNames[j];
                                }
                                mSourceFileNames = tempNames;
                            }
                            else
                            {
                                mSourceFileNames = new string[mSourceFileNamesLength];
                            }
                            while (lines-- > 0)
                            {
                                line = file.ReadLine();

                                Char[]   separator = { ':' };
                                string[] tokens    = line.Split(separator, 2);
                                mSourceFileNames[localFileIndex + int.Parse(tokens[0])] = tokens[1];
                            }
                        }
                        else if (line.IndexOf("ADDRS:") == 0)
                        {
                            int lines    = int.Parse(line.Substring(6));
                            int baseZone = 0;
                            if (mLabelInfoByZone.Count > 0)
                            {
                                baseZone = mLabelInfoByZone.Keys.Max();
                            }
                            while (lines-- > 0)
                            {
                                line = file.ReadLine();
                                string[] tokens   = line.Split(':');
                                AddrInfo addrInfo = new AddrInfo();
                                addrInfo.mAddr = int.Parse(tokens[0].Substring(1), NumberStyles.HexNumber);
                                addrInfo.mZone = int.Parse(tokens[1]);
                                if (addrInfo.mZone > 0)
                                {
                                    addrInfo.mZone += baseZone;
                                }
                                addrInfo.mFile = localFileIndex + int.Parse(tokens[2]);
                                addrInfo.mLine = int.Parse(tokens[3]) - 1;  // Files lines are 1 based in the debug file
                                                                            //								mAddrInfoByAddr.Add(addrInfo.mAddr, addrInfo);
                                mAddrInfoByAddr[addrInfo.mAddr] = addrInfo;
                            }
                        }
                        else if (line.IndexOf("LABELS:") == 0)
                        {
                            int lines    = int.Parse(line.Substring(7));
                            int baseZone = 0;
                            if (mLabelInfoByZone.Count > 0)
                            {
                                baseZone = mLabelInfoByZone.Keys.Max() + 1;
                            }
                            while (lines-- > 0)
                            {
                                line = file.ReadLine();
                                string[]  tokens    = line.Split(':');
                                LabelInfo labelInfo = new LabelInfo();
                                labelInfo.mAddr = int.Parse(tokens[0].Substring(1), NumberStyles.HexNumber);
                                labelInfo.mZone = int.Parse(tokens[1]);
                                if (labelInfo.mZone > 0)
                                {
                                    labelInfo.mZone += baseZone;    // Helps to distinguish zones for multiple PDB files
                                }
                                labelInfo.mLabel  = tokens[2];
                                labelInfo.mUsed   = int.Parse(tokens[3]) == 1;
                                labelInfo.mMemory = int.Parse(tokens[4]) == 1;
                                if (labelInfo.mLabel.Equals("APUCode_Start"))
                                {
                                    mAPUCode_Start = labelInfo.mAddr;
                                }
                                mAllLabels.Add(labelInfo);
                                mLabelInfoByAddr.Add(labelInfo.mAddr, labelInfo);
                                mLabelInfoByZone.Add(labelInfo.mZone, labelInfo);
                                mLabelInfoByLabel.Add(labelInfo.mLabel, labelInfo);
                            }
                        }
                    }

                    mAllLabels.Sort((a, b) => b.mLabel.Length.CompareTo(a.mLabel.Length));

                    file.Close();
                }
                int l;
                // Only process new names this iteration
                // Use mSourceIncludes
                for (l = localFileIndex; l < mSourceFileNamesLength; l++)
                {
                    string name = mSourceFileNames[l];
                    try
                    {
                        List <string> aFile   = new List <string>();
                        string        newPath = name;
                        if (!System.IO.File.Exists(newPath))
                        {
                            foreach (string prefix in mSourceIncludes)
                            {
                                string newName = System.IO.Path.Combine(prefix, name);
                                newPath = newName;
                                if (!System.IO.File.Exists(newPath))
                                {
                                    newPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(commandLineArgs[i]), newName);
                                    if (!System.IO.File.Exists(newPath))
                                    {
                                        newPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(commandLineArgs[i]), newName);
                                        if (!System.IO.File.Exists(newPath))
                                        {
                                            newPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(commandLineArgs[i]), System.IO.Path.GetFileName(newName));
                                            if (!System.IO.File.Exists(newPath))
                                            {
                                                newPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(commandLineArgs[i]) + "..\\", System.IO.Path.GetFileName(newName));
                                            }
                                        }
                                    }
                                }

                                if (System.IO.File.Exists(newPath))
                                {
                                    break;
                                }
                            }
                        }
                        using (System.IO.StreamReader file = new System.IO.StreamReader(newPath))
                        {
                            while ((line = file.ReadLine()) != null)
                            {
                                aFile.Add(line);
                            }
                            file.Close();
                        }
                        mSourceFiles.Add(aFile);
                        mSourceFileNamesFound.Add(newPath);
                    }
                    catch (System.Exception)
                    {
                        mSourceFiles.Add(new List <string>());
                        mSourceFileNamesFound.Add("");
                    }
                }
            }

            int thePrevAddr = -1;

            foreach (KeyValuePair <int, AddrInfo> pair in mAddrInfoByAddr)
            {
                pair.Value.mPrevAddr = thePrevAddr;
                thePrevAddr          = pair.Value.mAddr;
            }
            thePrevAddr = -1;
            foreach (KeyValuePair <int, AddrInfo> pair in mAddrInfoByAddr.Reverse())
            {
                pair.Value.mNextAddr = thePrevAddr;
                thePrevAddr          = pair.Value.mAddr;
            }
        }