Exemplo n.º 1
0
        public void SelectAPIEvent(Logging.TIMELINE_EVENT evt)
        {
            SelectedAPIEvent = null;
            SelectedEntity   = null;
            _selectedNode    = null;

            if (_rootTrace == null)
            {
                return;
            }

            switch (evt.TimelineEventType)
            {
            case Logging.eTimelineEvent.ProcessStart:
            case Logging.eTimelineEvent.ProcessEnd:
                TraceRecord?trace = _rootTrace.GetTraceByID(evt.ID);
                if (trace == null)
                {
                    return;
                }

                foreach (var node in sbgraph.Vertices)
                {
                    if (node.reference == trace)
                    {
                        _selectedNode = node;
                    }
                }
                break;

            case Logging.eTimelineEvent.ThreadStart:
            case Logging.eTimelineEvent.ThreadEnd:
                ProtoGraph?graph = _rootTrace.GetProtoGraphByTID(evt.ID);
                if (graph == null)
                {
                    return;
                }

                foreach (var node in sbgraph.Vertices)
                {
                    if (node.reference == graph)
                    {
                        _selectedNode = node;
                    }
                }
                break;

            case Logging.eTimelineEvent.APICall:
            {
                SelectedAPIEvent = evt;
                if (_timelineEventEntities.TryGetValue(evt, out ItemNode? newSelectedEntity))
                {
                    SelectedEntity = newSelectedEntity;
                    _selectedNode  = newSelectedEntity;
                }
            }
            break;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// This is just an alias for  RecordLogEvent( filter: TextError);
 /// </summary>
 /// <param name="text">Error text</param>
 /// <param name="graph">Graph the error applies to (optional)</param>
 /// <param name="trace">Trace the error applies to (optional)</param>
 public static void RecordError(string text, ProtoGraph?graph = null, TraceRecord?trace = null)
 {
     if (rgatState.NetworkBridge.Connected)
     {
         rgatState.NetworkBridge.SendLog(text, LogFilterType.Error);
     }
     RecordLogEvent(text: text, graph: graph, trace: trace, filter: LogFilterType.Error);
 }
Exemplo n.º 3
0
        public bool ExecutePrevInstruction()
        {
            while (traceFile.TryGetPrev(out var record))
            {
                ProcessRecord(record, true);
                if (record is TraceRecord trace &&
                    !ReferenceEquals(trace, currentTraceRecord))
                {
                    currentTraceRecord = trace;
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 4
0
        public TraceApplicationEngine(string traceFilePath, IEnumerable <NefFile> contracts)
        {
            this.contracts = contracts.ToDictionary(c => Neo.SmartContract.Helper.ToScriptHash(c.Script), c => (Script)c.Script);
            traceFile      = new TraceFile(traceFilePath, this.contracts);

            while (traceFile.TryGetNext(out var record))
            {
                ProcessRecord(record);
                if (record is TraceRecord trace)
                {
                    currentTraceRecord = trace;
                    break;
                }
            }
        }
Exemplo n.º 5
0
        /*
         * public static LOG_EVENT[] GetErrorMessages()
         * {
         *  lock (_messagesLock)
         *  {
         *      UnseenAlerts = 0;
         *      return _logMessages.Where(x => x.LogType == eLogFilterBaseType.Text && x.Filter == LogFilterType.TextError).ToArray();
         *
         *  }
         * }*/

        /// <summary>
        /// Fetch messages for a filter and clear pending alerts
        /// </summary>
        /// <param name="trace">Specific trace to getch messages for</param>
        /// <param name="filters">Filters to match</param>
        /// <returns>Array of log events</returns>
        public static LOG_EVENT[] GetLogMessages(TraceRecord?trace, bool[] filters)
        {
            lock (_messagesLock)
            {
                UnseenAlerts = 0;
                if (trace == null)
                {
                    return(_logMessages.Where(x => filters[(int)x.Filter] == true).ToArray());
                }
                else
                {
                    return(_logMessages.Where(x => x.Trace == trace).Where(x => filters[(int)x.Filter] == true).ToArray());
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Draw a trace selector
        /// </summary>
        /// <param name="trace">Parent trace</param>
        /// <param name="abbreviate">Make the label a bit shorter to fit in the preview pane width</param>
        /// <returns>Selected graph or null</returns>
        public static PlottedGraph?Draw(TraceRecord?trace, bool abbreviate = false)
        {
            if (trace is null)
            {
                if (ImGui.BeginChild(ImGui.GetID("TraceSelect"), new Vector2(ImGui.GetContentRegionAvail().X - 4, ImGui.GetContentRegionAvail().Y)))
                {
                    ImGuiUtils.DrawRegionCenteredText($"No selected trace");
                    ImGui.EndChild();
                }
                return(null);
            }

            PlottedGraph?selectedGraph = null;

            if (ImGui.BeginChild(ImGui.GetID("TraceSelect"), new Vector2(ImGui.GetContentRegionAvail().X - 4, 52)))
            {
                ImGui.PushStyleVar(ImGuiStyleVar.CellPadding, new Vector2(1, 1));
                if (ImGui.BeginTable("#TraceSelectorTable", 2))
                {
                    ImGui.TableSetupColumn("#IconsTraceSel", ImGuiTableColumnFlags.WidthFixed, 35);
                    ImGui.TableNextRow();
                    DrawTraceCombo(trace, abbreviate);

                    ImGui.TableNextRow();
                    DrawThreadSelectorCombo(trace, out selectedGraph, abbreviate);
                    ImGui.EndTable();
                }
                ImGui.PopStyleVar();
                ImGui.EndChild();
            }

            if (selectedGraph is not null)
            {
                rgatState.SetActiveGraph(selectedGraph);
            }
            return(selectedGraph);
        }
Exemplo n.º 7
0
        public void InitChartFromTrace(TraceRecord trace)
        {
            lock (_lock)
            {
                if (trace != _rootTrace)
                {
                    sbgraph.Clear();
                    layout.VerticesPositions.Clear();
                    _rootTrace = trace;
                    addedNodes.Clear();
                }

                bool needLayout = trace.TimelineItemsCount != timelineItemsOnChartDraw;
                if (needLayout && !_layoutActive)
                {
                    Logging.TIMELINE_EVENT[] entries = trace.GetTimeLineEntries();
                    timelineItemsOnChartDraw = entries.Length;
                    //StopLayout();
                    AddThreadItems(null, trace);

                    /*
                     * KKLayoutParameters layoutParams = new KKLayoutParameters()
                     * {
                     *  Height = chartSize.Y - (2 * padding),
                     *  Width = chartSize.X - (2 * padding),
                     *  LengthFactor = 1,
                     *  DisconnectedMultiplier = 2,
                     *  ExchangeVertices = true
                     * };
                     * layout = new GraphShape.Algorithms.Layout.KKLayoutAlgorithm<ItemNode,
                     *  Edge<ItemNode>, BidirectionalGraph<ItemNode, Edge<ItemNode>>>(sbgraph, parameters: layoutParams);
                     */
                    FitNodesToChart();
                    _computeRequired = true;
                }
            }
        }
Exemplo n.º 8
0
        private static void DrawThreadSelectorCombo(TraceRecord?trace, out PlottedGraph?selectedGraph, bool abbreviate)
        {
            selectedGraph = null;
            ProtoGraph?graph = rgatState.ActiveGraph?.InternalProtoGraph;

            if (trace is not null && graph is not null)
            {
                string selString = $"{(abbreviate ? "TID" : "Thread")} {graph.ThreadID}: {graph.FirstInstrumentedModuleName}";
                if (graph.NodeCount == 0)
                {
                    selString += " [Uninstrumented]";
                }
                List <PlottedGraph> graphs = trace.GetPlottedGraphs();
                if (ImGui.TableNextColumn())
                {
                    ImGui.AlignTextToFramePadding();
                    ImGuiUtils.DrawHorizCenteredText($"{graphs.Count}x");
                    SmallWidgets.MouseoverText($"This trace has {graphs.Count} thread{(graphs.Count != 1 ? 's' : "")}");
                }

                if (ImGui.TableNextColumn())
                {
                    ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X - 35);
                    if (ImGui.BeginCombo("##SelectorThreadCombo", selString))
                    {
                        foreach (PlottedGraph selectablegraph in graphs)
                        {
                            string caption   = $"{selectablegraph.TID}: {selectablegraph.InternalProtoGraph.FirstInstrumentedModuleName}";
                            int    nodeCount = selectablegraph.GraphNodeCount();
                            if (nodeCount == 0)
                            {
                                ImGui.PushStyleColor(ImGuiCol.Text, Themes.GetThemeColourUINT(Themes.eThemeColour.Dull1));
                                caption += " [Uninstrumented]";
                            }
                            else
                            {
                                ImGui.PushStyleColor(ImGuiCol.Text, Themes.GetThemeColourUINT(Themes.eThemeColour.WindowText));
                                caption += $" [{nodeCount} nodes]";
                            }

                            if (ImGui.Selectable(caption, graph.ThreadID == selectablegraph.TID) && nodeCount > 0)
                            {
                                selectedGraph = selectablegraph;
                            }
                            if (ImGui.IsItemHovered())
                            {
                                ImGui.BeginTooltip();
                                ImGui.Text($"Thread Start: 0x{selectablegraph.InternalProtoGraph.StartAddress:X} [{selectablegraph.InternalProtoGraph.StartModuleName}]");
                                if (selectablegraph.InternalProtoGraph.NodeList.Count > 0)
                                {
                                    NodeData?n = selectablegraph.InternalProtoGraph.GetNode(0);
                                    if (n is not null)
                                    {
                                        string insBase = System.IO.Path.GetFileName(graph.ProcessData.GetModulePath(n.GlobalModuleID));
                                        ImGui.Text($"First Instrumented: 0x{n.Address:X} [{insBase}]");
                                    }
                                }
                                ImGui.EndTooltip();
                            }
                            ImGui.PopStyleColor();
                        }
                        ImGui.EndCombo();
                    }
                    ImGui.SameLine();
                    ImGui.Text($"{ImGuiController.FA_ICON_COG}");
                }
            }
        }
Exemplo n.º 9
0
        private void DrawAnalysisTab(TraceRecord?activeTrace)
        {
            if (activeTrace == null || !ImGui.BeginTabItem("Timeline") || chart is null)
            {
                return;
            }

            _currentTab = "Timeline";

            float height        = ImGui.GetContentRegionAvail().Y;
            float width         = ImGui.GetContentRegionAvail().X;
            float sidePaneWidth = 300;

            if (height < 50 || width < 50)
            {
                ImGui.EndTabItem();
                return;
            }

            chart !.InitChartFromTrace(activeTrace);

            SandboxChart.ItemNode?selectedNode = chart.GetSelectedNode;
            if (ImGui.BeginTable("#TaTTable", 2, ImGuiTableFlags.Resizable))
            {
                ImGui.TableSetupColumn("#TaTTEntryList", ImGuiTableColumnFlags.None | ImGuiTableColumnFlags.WidthFixed, sidePaneWidth * 2f);
                ImGui.TableSetupColumn("#TaTTChart");

                ImGui.TableNextRow();
                if (ImGui.TableNextColumn())
                {
                    if (ImGui.BeginChild("#ijdcccfgo", ImGui.GetContentRegionAvail() - new Vector2(0, 5)))
                    {
                        TraceSelector.Draw(activeTrace);
                        ImGui.Separator();
                        ImGui.Text("Event Listing");

                        if (ImGui.BeginChild("#iosfjhvs", ImGui.GetContentRegionAvail() - new Vector2(0, selectedNode is null ? 0 : 250)))
                        {
                            DrawEventListTable(activeTrace, selectedNode);
                            ImGui.EndChild();
                        }


                        if (selectedNode is not null)
                        {
                            ImGui.PushStyleColor(ImGuiCol.ChildBg, Themes.GetThemeColourUINT(Themes.eThemeColour.Frame));
                            if (ImGui.BeginChild(ImGui.GetID("#ijdcccfgo"), new Vector2(ImGui.GetContentRegionAvail().X, 245)))
                            {
                                DrawEventInfoPanel(height, activeTrace, selectedNode);
                                ImGui.EndChild();
                            }
                            ImGui.PopStyleColor();
                        }
                        ImGui.EndChild();
                    }
                }

                if (ImGui.TableNextColumn())
                {
                    chart.Draw(_controller !.UnicodeFont);
                }
                ImGui.EndTable();
            }


            ImGui.EndTabItem();
        }
Exemplo n.º 10
0
 /// <summary>
 /// Declares an error and seperately adds the exception details to the log
 /// </summary>
 /// <param name="message">Exception context text</param>
 /// <param name="e">Exception</param>
 /// <param name="graph">Graph the error applies to (optional)</param>
 /// <param name="trace">Trace the error applies to (optional)</param>
 public static void RecordException(string message, Exception e, ProtoGraph?graph = null, TraceRecord?trace = null)
 {
     if (rgatState.NetworkBridge.Connected)
     {
         rgatState.NetworkBridge.SendLog(message, LogFilterType.Error);
     }
     RecordLogEvent(text: message, graph: graph, trace: trace, filter: LogFilterType.Error);
     RecordLogEvent(text: e.ToString(), graph: graph, trace: trace, filter: LogFilterType.Info);
     Console.WriteLine(e);
 }
Exemplo n.º 11
0
        /// <summary>
        /// Display a message in the logfile/message window.
        /// Will also be shown on the UI alert pane with the Alert/Error options
        /// </summary>
        /// <param name="text">Message to display</param>
        /// <param name="filter">The LogFilterType category of the log entry
        /// </param>
        /// <param name="graph">Graph this applies to. If aimed at a trace, just use any graph of the trace</param>
        /// <param name="trace">Process this applies to</param>

        public static void RecordLogEvent(string text, LogFilterType filter = LogFilterType.Info, ProtoGraph?graph = null, TraceRecord?trace = null)
        {
            TEXT_LOG_EVENT log = new TEXT_LOG_EVENT(filter: filter, text: text);

            if (graph != null)
            {
                log.SetAssociatedGraph(graph);
            }
            if (trace != null)
            {
                log.SetAssociatedTrace(trace);
            }

            lock (_messagesLock)
            {
                //write all logs to the logfile in bulk logging mode
                if (GlobalConfig.Settings.Logs.BulkLogging)
                {
                    try
                    {
                        WriteToDebugFile(log);
                    }
                    catch (Exception e)
                    {
                        GlobalConfig.Settings.Logs.BulkLogging = false;
                        Logging.RecordLogEvent($"Error: Not able to write to bulk log file {e.Message}. Another rgat may be using it. Disabling bulk logging.");
                    }
                }

                //write non-bulklog files to the UI log pane
                if (filter != LogFilterType.BulkDebugLogFile)
                {
                    _logMessages.Add(log);
                    if (log.Filter == LogFilterType.Alert || log.Filter == LogFilterType.Error)
                    {
                        UnseenAlerts += 1;
                        _alertNotifications.Add(log);
                        _lastAlert = DateTime.Now;
                    }
                    MessageCounts[(int)filter] += 1;
                }
            }

            //todo remove after debug done
            if (filter == LogFilterType.Error)
            {
                WriteConsole(text, ConsoleColor.Yellow);
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Set the trace of the active graph
 /// </summary>
 /// <param name="trace"></param>
 public void SetActiveTrace(TraceRecord?trace) => ActiveTrace = trace;
Exemplo n.º 13
0
        /// <summary>
        /// Draw the preview graph widget
        /// </summary>
        public void DrawWidget(Vector2 mainWidgetSize)
        {
            bool         showToolTip      = false;
            PlottedGraph?latestHoverGraph = null;
            TraceRecord? activeTrace      = ActiveTrace;

            if (activeTrace == null)
            {
                return;
            }


            float captionHeight = ImGui.CalcTextSize("123456789").Y;

            DrawnPreviewGraphs = activeTrace.GetPlottedGraphs();
            List <int> indexes = GetGraphOrder(trace: activeTrace, graphs: DrawnPreviewGraphs);
            uint       captionBackgroundcolor = Themes.GetThemeColourUINT(Themes.eThemeColour.PreviewTextBackground);

            ImGui.PushStyleVar(ImGuiStyleVar.CellPadding, new Vector2(0, CONSTANTS.UI.PREVIEW_PANE_Y_SEP));

            //Graph drawing loop
            if (ImGui.BeginTable("PrevGraphsTable", 1, ImGuiTableFlags.Borders, new Vector2(CONSTANTS.UI.PREVIEW_PANE_WIDTH, ImGui.GetContentRegionAvail().Y)))
            {
                foreach (int graphIdx in indexes)
                {
                    PlottedGraph plot     = DrawnPreviewGraphs[graphIdx];
                    float        xPadding = CONSTANTS.UI.PREVIEW_PANE_X_PADDING;
                    if (plot == null || plot.GraphNodeCount() == 0)
                    {
                        continue;
                    }

                    ImGui.TableNextRow();
                    ImGui.TableSetColumnIndex(0);

                    if (DrawPreviewGraph(plot, xPadding, captionHeight, captionBackgroundcolor, out bool canHover, mainWidgetSize))
                    {
                        var MainGraphs = plot.InternalProtoGraph.TraceData.GetPlottedGraphs();
                        HandleClickedGraph(MainGraphs[graphIdx]);
                    }

                    if (canHover && ImGui.IsItemHovered(ImGuiHoveredFlags.None) && !(ImGui.IsMouseDown(ImGuiMouseButton.Left)))
                    {
                        latestHoverGraph = plot;
                        showToolTip      = true;
                    }
                }
                ImGui.EndTable();
            }
            ImGui.PopStyleVar();


            ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(5, 5));
            ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(5, 5));
            ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(5, 5));
            ImGui.PushStyleColor(ImGuiCol.Border, 0x77999999);

            HoveredGraph = latestHoverGraph;
            bool showedCtx = HandlePreviewGraphContextMenu();

            bool veryRecentPopup = showedCtx || _lastCtxMenu.AddMilliseconds(250) > DateTime.Now;

            if (showToolTip && !veryRecentPopup && HoveredGraph is not null)
            {
                DrawGraphTooltip(HoveredGraph);
            }
            ImGui.PopStyleVar(3);
            ImGui.PopStyleColor();
        }
Exemplo n.º 14
0
 /// <summary>
 /// Set the initial trace
 /// </summary>
 /// <param name="trace"></param>
 public void SetFirstTrace(TraceRecord trace)
 {
     FirstTrace = trace;
     StartTime  = DateTime.Now;
 }