Example #1
0
        public void SendAssembly(bool noDisplay = false)
        {
            AD7Util.Log("SendAssembly");
            ASMWindow_CurrentLineUpdated.Reset();
            ASMWindow_NextAddress1Updated.Reset();
            ASMWindow_NextLine1Updated.Reset();

            UInt32 xAddress = mCurrentAddress.Value;
            var xSourceInfos = mDebugInfoDb.GetSourceInfos(xAddress);
            AD7Util.Log("SendAssembly - SourceInfos retrieved for address 0x{0}", xAddress.ToString("X8"));
            if (xSourceInfos.Count > 0)
            {
                //We should be able to display the asesembler source for any address regardless of whether a C#
                //line is associated with it.
                //However, we do not store all labels in the debug database because that would make the compile
                //time insane.
                //So:
                // - We take the current address amd find the method it is part of
                // - We use the method header label as a start point and find all asm labels till the method footer label
                // - We then find all the asm for these labels and display it.

                Label[] xLabels = mDebugInfoDb.GetMethodLabels(xAddress);
                AD7Util.Log("SendAssembly - MethodLabels retrieved");
                // get the label of our current position, or the closest one before
                var curPosLabel = xLabels.Where(i => i.Address <= xAddress).OrderByDescending(i => i.Address).FirstOrDefault();
                // if curPosLabel is null, grab the first one.
                if (curPosLabel == null)
                {
                    curPosLabel = xLabels[0];
                }

                var curPosIndex = Array.IndexOf(xLabels, curPosLabel);
                // we want 50 items before and after the current item, so 100 in total.
                var itemsBefore = 10;
                var itemsAfter = 10;

                if (curPosIndex < itemsBefore)
                {
                    // there are no 50 items before the current one, so adjust
                    itemsBefore = curPosIndex;
                }
                if ((curPosIndex + itemsAfter) >= xLabels.Length)
                {
                    // there are no 50 items after the current one, so adjust
                    itemsAfter = xLabels.Length - curPosIndex;
                }

                var newArr = new Label[itemsBefore + itemsAfter];
                for (int i = 0; i < newArr.Length; i++)
                {
                    newArr[i] = xLabels[(curPosIndex - itemsBefore) + i];
                }
                xLabels = newArr;

                //The ":" has to be added in because labels in asm code have it on the end - it's easier to add it here than
                //strip them out of the read asm
                var xLabelNames = xLabels.Select(x => x.Name + ":").ToList();

                // Get assembly source
                var xCode = AsmSource.GetSourceForLabels(Path.ChangeExtension(mISO, ".asm"), xLabelNames);
                AD7Util.Log("SendAssembly - SourceForLabels retrieved");

                // Get label for current address.
                // A single address can have multiple labels (IL, Asm). Because of this we search
                // for the one with the Asm tag. We dont have the tags in this debug info though,
                // so instead if there is more than one label we use the longest one which is the Asm tag.
                string xCurrentLabel = "";
                var xCurrentLabels = mDebugInfoDb.GetLabels(xAddress);
                if (xCurrentLabels.Length > 0)
                {
                    xCurrentLabel = xCurrentLabels.OrderBy(q => q.Length).Last();
                }
                if (string.IsNullOrEmpty(xCurrentLabel))
                {
                    xCurrentLabel = "NO_METHOD_LABEL_FOUND";
                }

                // Insert filter labels list as THIRD(!) line of our data stream
                string filterLabelsList = "";
                foreach (var addressInfo in INT3sSet)
                {
                    //"We have to add the ".00:" because of how the ASM window works...
                    filterLabelsList += "|" + addressInfo.Value + ".00";
                }
                if (filterLabelsList.Length > 0)
                {
                    filterLabelsList = filterLabelsList.Substring(1);
                }
                xCode.Insert(0, filterLabelsList + "\r\n");
                // Insert parameters as SECOND(!) line of our data stream
                xCode.Insert(0, (noDisplay ? "NoDisplay" : "") + "|" + (ASMSteppingMode ? "AsmStepMode" : "") + "\r\n");
                // Insert current line's label as FIRST(!) line of our data stream
                xCode.Insert(0, xCurrentLabel + "\r\n");
                //THINK ABOUT THE ORDER that he above lines occur in and where they insert data into the stream - don't switch it!
                AD7Util.Log("SendAssembly - Sending through pipe now");
                mDebugDownPipe.SendCommand(Debugger2Windows.AssemblySource, Encoding.UTF8.GetBytes(xCode.ToString()));
                AD7Util.Log("SendAssembly - Done");
            }
        }
Example #2
0
        public void SendAssembly(bool noDisplay = false)
        {
            AD7Util.Log("SendAssembly");
            ASMWindow_CurrentLineUpdated.Reset();
            ASMWindow_NextAddress1Updated.Reset();
            ASMWindow_NextLine1Updated.Reset();

            UInt32 xAddress     = mCurrentAddress.Value;
            var    xSourceInfos = mDebugInfoDb.GetSourceInfos(xAddress);

            AD7Util.Log("SendAssembly - SourceInfos retrieved for address 0x{0}", xAddress.ToString("X8"));
            if (xSourceInfos.Count > 0)
            {
                //We should be able to display the asesembler source for any address regardless of whether a C#
                //line is associated with it.
                //However, we do not store all labels in the debug database because that would make the compile
                //time insane.
                //So:
                // - We take the current address amd find the method it is part of
                // - We use the method header label as a start point and find all asm labels till the method footer label
                // - We then find all the asm for these labels and display it.

                Label[] xLabels = mDebugInfoDb.GetMethodLabels(xAddress);
                AD7Util.Log("SendAssembly - MethodLabels retrieved");
                // get the label of our current position, or the closest one before
                var curPosLabel = xLabels.Where(i => i.Address <= xAddress).OrderByDescending(i => i.Address).FirstOrDefault();
                // if curPosLabel is null, grab the first one.
                if (curPosLabel == null)
                {
                    curPosLabel = xLabels[0];
                }

                var curPosIndex = Array.IndexOf(xLabels, curPosLabel);
                // we want 50 items before and after the current item, so 100 in total.
                var itemsBefore = 10;
                var itemsAfter  = 10;

                if (curPosIndex < itemsBefore)
                {
                    // there are no 50 items before the current one, so adjust
                    itemsBefore = curPosIndex;
                }
                if ((curPosIndex + itemsAfter) >= xLabels.Length)
                {
                    // there are no 50 items after the current one, so adjust
                    itemsAfter = xLabels.Length - curPosIndex;
                }

                var newArr = new Label[itemsBefore + itemsAfter];
                for (int i = 0; i < newArr.Length; i++)
                {
                    newArr[i] = xLabels[(curPosIndex - itemsBefore) + i];
                }
                xLabels = newArr;

                //The ":" has to be added in because labels in asm code have it on the end - it's easier to add it here than
                //strip them out of the read asm
                var xLabelNames = xLabels.Select(x => x.Name + ":").ToList();

                // Get assembly source
                var xCode = AsmSource.GetSourceForLabels(Path.ChangeExtension(mISO, ".asm"), xLabelNames);
                AD7Util.Log("SendAssembly - SourceForLabels retrieved");

                // Get label for current address.
                // A single address can have multiple labels (IL, Asm). Because of this we search
                // for the one with the Asm tag. We dont have the tags in this debug info though,
                // so instead if there is more than one label we use the longest one which is the Asm tag.
                string xCurrentLabel  = "";
                var    xCurrentLabels = mDebugInfoDb.GetLabels(xAddress);
                if (xCurrentLabels.Length > 0)
                {
                    xCurrentLabel = xCurrentLabels.OrderBy(q => q.Length).Last();
                }
                if (string.IsNullOrEmpty(xCurrentLabel))
                {
                    xCurrentLabel = "NO_METHOD_LABEL_FOUND";
                }

                // Insert filter labels list as THIRD(!) line of our data stream
                string filterLabelsList = "";
                foreach (var addressInfo in INT3sSet)
                {
                    //"We have to add the ".00:" because of how the ASM window works...
                    filterLabelsList += "|" + addressInfo.Value + ".00";
                }
                if (filterLabelsList.Length > 0)
                {
                    filterLabelsList = filterLabelsList.Substring(1);
                }
                xCode.Insert(0, filterLabelsList + "\r\n");
                // Insert parameters as SECOND(!) line of our data stream
                xCode.Insert(0, (noDisplay ? "NoDisplay" : "") + "|" + (ASMSteppingMode ? "AsmStepMode" : "") + "\r\n");
                // Insert current line's label as FIRST(!) line of our data stream
                xCode.Insert(0, xCurrentLabel + "\r\n");
                //THINK ABOUT THE ORDER that he above lines occur in and where they insert data into the stream - don't switch it!
                AD7Util.Log("SendAssembly - Sending through pipe now");
                mDebugDownPipe.SendCommand(Debugger2Windows.AssemblySource, Encoding.UTF8.GetBytes(xCode.ToString()));
                AD7Util.Log("SendAssembly - Done");
            }
        }