File: stackbrowser.h

package info (click to toggle)
kcachegrind 4%3A25.04.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,964 kB
  • sloc: cpp: 32,149; xml: 403; perl: 325; python: 235; sh: 8; makefile: 6
file content (99 lines) | stat: -rw-r--r-- 2,216 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
    This file is part of KCachegrind.

    SPDX-FileCopyrightText: 2003-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>

    SPDX-License-Identifier: GPL-2.0-only
*/

#ifndef STACKBROWSER_H
#define STACKBROWSER_H

#include "tracedata.h"

// A history of selected functions within stacks

class Stack
{
public:
    explicit Stack(TraceFunction*);

    // extend the stack at top/bottom if possible
    bool contains(TraceFunction*);

    void extendBottom();
    void extendTop();

    // search for a function on stack calling specified function.
    // if found, return upper part with new function call
    Stack* split(TraceFunction*);

    // increment reference count
    void ref() { _refCount++; }
    // decrement reference count
    bool deref() { return --_refCount; }
    int refCount() const { return _refCount; }

    TraceFunction* top() { return _top; }
    TraceCallList calls() { return _calls; }
    TraceFunction* caller(TraceFunction*, bool extend);
    TraceFunction* called(TraceFunction*, bool extend);

    QString toString();

private:
    Stack(TraceFunction* top, TraceCallList list);

    // at the top of the stack we have a function...
    TraceFunction* _top;
    // list ordered from top to bottom
    TraceCallList _calls;
    int _refCount;
};

class HistoryItem
{
public:
    HistoryItem(Stack*, TraceFunction*);
    ~HistoryItem();

    Stack* stack() { return _stack; }
    TraceFunction* function() { return _function; }
    HistoryItem* last() { return _last; }
    HistoryItem* next() { return _next; }
    void setLast(HistoryItem* h) { _last = h; }
    void setNext(HistoryItem* h) { _next = h; }

private:

    HistoryItem *_last, *_next;
    Stack* _stack;
    TraceFunction* _function;
};


class StackBrowser
{
public:
    StackBrowser();
    ~StackBrowser();

    // A function was selected. This creates a new history entry
    HistoryItem* select(TraceFunction*);

    HistoryItem* current() { return _current; }
    bool canGoBack();
    bool canGoForward();
    bool canGoUp();
    bool canGoDown();
    HistoryItem* goBack();
    HistoryItem* goForward();
    HistoryItem* goUp();
    HistoryItem* goDown();

private:
    HistoryItem* _current;
};


#endif