// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \page creator-stack-view.html
    \previouspage creator-reference.html

    \ingroup creator-reference-debugger

    \title Viewing call stack trace

    \brief View the nested function calls leading to the current position as a
    call stack trace.

    When the application being debugged is interrupted, \QC displays the nested
    function calls leading to the current position as a call stack trace. This
    stack trace is built up from call stack frames, each representing a
    particular function. For each function, \QC tries to retrieve the file name
    and line number of the corresponding source file. This data is shown in the
    \uicontrol Stack view.

    \image {qtcreator-debug-stack.png} {Stack view}

    Since the call stack leading to the current position may originate or go
    through code for which no debug information is available, not all stack
    frames have corresponding source locations. Stack frames without
    corresponding source locations are grayed out.

    If you select a frame with a known source location, the text editor jumps to
    the corresponding location and updates the
    \l {Local variables and function parameters}{Locals} and
    \l {Evaluating expressions}{Expressions} views, making it seem like the
    application was interrupted before entering the function.

    \section1 Loading QML stack

    To find out which QML file is causing a Qt Quick application to crash,
    select \uicontrol {Load QML Stack} in the context menu in the
    \uicontrol Stack view. The debugger tries to retrieve the JavaScript stack
    from the stopped executable and prepends the frames to the C++ frames,
    should it find any. You can select a frame in the QML stack to open the QML
    file in the editor.

    \sa {Debug}{How to: Debug}, {Debugging}, {Debuggers},
    {Setting breakpoints}
*/

/*!
    \page creator-breakpoints-view.html
    \previouspage creator-reference.html

    \ingroup creator-reference-debugger

    \title Setting breakpoints

    \brief Set breakpoints to interrupt the application.

    You can associate breakpoints with:

    \list

        \li Source code files and lines

        \li Functions

        \li Addresses

        \li Throwing and catching exceptions

        \li Executing and forking processes

        \li Executing some system calls

        \li Changes in a block of memory at a particular address when an
            application is running

        \li Emitting QML signals

        \li Throwing JavaScript exceptions

    \endlist

    A breakpoint interrupts the application every time the application reaches
    its location unless you specify a boolean condition for it. The breakpoint
    evaluates the expression each time the application passes it, and the
    application stops only if the condition evaluates to \c true.

    \section1 Unclaimed and claimed breakpoints

    Breakpoints come in two varieties: \c unclaimed and \c claimed.
    An unclaimed breakpoint represents a task to interrupt the debugged
    application and passes the control to you later. It has two states:
    \c pending and \c implanted.

    Unclaimed breakpoints are stored as a part of a session and exist
    independently of whether an application is being debugged or not. They are
    listed in the \uicontrol {Breakpoint Preset} view and in the editor using the
    \inlineimage {icons/qtcreator-unclaimed-breakpoint-icon.png} {Unclaimed Breakpoint}
    (\uicontrol {Unclaimed Breakpoint}) icon, when they refer to a position
    in code.

    \image {qtcreator-debugger-breakpoint-preset.webp} {Breakpoint Preset view}

    When a debugger starts, the debugging backend identifies breakpoints
    from the set of unclaimed breakpoints that might be handled by the
    debugged application and claims them for its own exclusive use. Claimed
    breakpoints are listed in the \uicontrol {Breakpoints} view of the
    running debugger. This view only exists while the debugger is running.

    When a debugger claims a breakpoint, the unclaimed breakpoint disappears
    from the \uicontrol {Breakpoint Preset} view, to appear as a pending
    breakpoint in the \uicontrol Breakpoints view.

    At various times, attempts are made to implant pending breakpoints into
    the debugged process. Successful implantation might create one or more
    implanted breakpoints, each associated with an actual address in
    the debugged breakpoint. The implantation might also move a breakpoint
    marker in the editor from an empty line to the next line for which the
    actual code was generated, for example. Implanted breakpoint icons don't
    have the hourglass overlay.

    When the debugger ends, its claimed breakpoints, both pending and
    implanted, will return to the unclaimed state and re-appear in the
    \uicontrol{Breakpoint Preset} view.

    When an implanted breakpoint is hit during the execution of the
    debugged application, control is passed back to you.
    You can then examine the state of the interrupted application, or
    continue execution either line-by-line or continuously.

    \image {qtcreator-debug-breakpoints.webp} {Breakpoints view}

    \sa {Add breakpoints}, {Debug}{How to: Debug}, {Debugging}, {Debuggers}
*/

/*!
    \page creator-how-to-add-breakpoints.html
    \previouspage creator-how-tos.html

    \ingroup creator-how-to-debug

    \title Add breakpoints

    To add breakpoints:

    \list 1

        \li Add a new breakpoint in one of the following ways:

            \list

                \li In the code editor, click the left margin or select \key F9
                    (\key F8 on \macos) on a particular line where you want the
                    application to stop.

                \li In the \uicontrol {Breakpoint Preset} view or the
                    \uicontrol Breakpoints view:

                    \list
                        \li Double-click the empty part of the view.
                            \image {qtcreator-debugger-breakpoint-preset.webp} {Breakpoint Preset view}
                        \li Right-click the view, and select
                            \uicontrol {Add Breakpoint} in the context menu.
                    \endlist
            \endlist

        \li In \uicontrol {Breakpoint type}, select the location in the
            application code where you want the application to stop.

            \image {qtcreator-add-breakpoint.webp} {Add Breakpoints dialog}
    \endlist

    Clear \uicontrol Enabled to make the breakpoint temporarily
    inoperative as if you had deleted it, but keep the information about the
    breakpoint, so that you can enable it again later.

    The other options to specify depend on the location you select, such as file
    name and line number, address, expression, or function name. The following
    table summarizes the advanced options.

    \table
    \header
        \li Option
        \li Value
    \row
        \li \uicontrol Condition
        \li The condition to evaluate before stopping at the breakpoint if the
            condition evaluates as \c true.
    \row
        \li \uicontrol {Ignore count}
        \li The number of times to ignore the breakpoint before the application
            stops.
    \row
        \li \uicontrol {Thread specification}
        \li
    \row
        \li \uicontrol Path
        \li Determines how to specify the path when setting breakpoints:
            \list
                \li \uicontrol {Use Engine Default} is the preferred setting of
                    the debugger engine.
                \li \uicontrol {Use Full Path} passes the full path to avoid
                    ambiguity if several modules contain files with the same
                    name. This is the engine default for CDB and LLDB.
                \li \uicontrol {Use File Name} passes the file name only. This is
                    useful when the location of the source tree does not match
                    the one used when building the modules. This is the engine
                    default for GDB as using full paths can be slow with it.
            \endlist
    \row
        \li \uicontrol Module
        \li Specify the module (base name of the library or executable) for
            function or file type breakpoints to speed up debugger startup
            (CDB, LLDB).
    \row
        \li \uicontrol Commands
        \li Commands to execute when the application stops. List one command per
            line. GDB executes the commands in the order in which you specify
            them.
    \row
        \li \uicontrol {Tracepoint only}
        \li A \e tracepoint lets you log information about the application
            without adding log statements or otherwise modifying your code.
            You can set conditions for the tracepoint.
    \row
        \li \uicontrol Message
        \li The tracepoint message to show in \l {Application Output}.
    \endtable

    \sa {Debug}{How to: Debug}, {Debugging}, {Debuggers},
    {Setting breakpoints}
*/

/*!
    \page creator-how-to-manage-breakpoints.html
    \previouspage creator-how-tos.html

    \ingroup creator-how-to-debug

    \title Manage breakpoints

    \section1 Move breakpoints

    To move a breakpoint:

    \list
        \li Drag a breakpoint marker to another line
            in the text editor.
        \li In the \uicontrol {Breakpoint Preset} view or the
             \uicontrol Breakpoints view, select
             \uicontrol {Edit Selected Breakpoints}, and set the
             line number in \uicontrol {Line number}.
            \image {qtcreator-add-breakpoint.webp} {Breakpoint options}
    \endlist

    \section1 Delete breakpoints

    To delete breakpoints:

    \list

        \li Select the breakpoint marker in the text editor.

        \li In the \uicontrol {Breakpoint Preset} view or the
            \uicontrol Breakpoints view:
            \list
                \li Select the breakpoint and select \key Delete.
                \li Select \uicontrol {Delete Selected Breakpoints},
                    \uicontrol {Delete Selected Breakpoints}, or
                    \uicontrol {Delete Breakpoints of File} in the
                    context menu.
            \endlist

    \endlist

    \section1 Turn breakpoints on and off

    To temporarily turn off a breakpoint without deleting it and losing associated
    data like conditions and commands:

    \list

        \li Right-click the breakpoint marker in the text editor and select
            \uicontrol{Disable Breakpoint}.

        \li Select a line that has a breakpoint and select \key Ctrl+F9
            (\key Ctrl+F8 on \macos).

        \li In the \uicontrol {Breakpoint Preset} view or the
            \uicontrol Breakpoints view:
            \list
                \li Select the breakpoint and select \key Space.
                \li Select \uicontrol {Disable Breakpoint} in the context menu.
            \endlist
    \endlist

    A hollow breakpoint icon in the text editor and the views indicates a
    disabled breakpoint. To re-enable a breakpoint, use any of the above
    methods.

    Other than data breakpoints retain their enabled or disabled state when the
    debugged application is restarted.

    \sa {Debug}{How to: Debug}, {Debugging}, {Debuggers},
    {Setting breakpoints}
*/

/*!
    \page creator-how-to-set-data-breakpoints.html
    \previouspage creator-how-tos.html

    \ingroup creator-how-to-debug

    \title Set data breakpoints

    A \e {data breakpoint} stops the application when data is read or written at the
    specified address.

    To set a data breakpoint at an address:

    \list 1

        \li In the \uicontrol {Breakpoint Preset} or \uicontrol Breakpoints
            view, select \uicontrol {Add Breakpoint} in the context menu.
            \image {qtcreator-add-breakpoint.webp} {Add Breakpoints dialog}

        \li In \uicontrol {Breakpoint type}, select
            \uicontrol {Break on data access at fixed address}.

        \li In \uicontrol Address, specify the address of the memory block.

        \li Select \uicontrol OK.

    \endlist

    If the address is displayed in the \uicontrol {Locals} or
    \uicontrol {Expressions} view, you can select
    \uicontrol {Add Data Breakpoint at Object's Address} in the
    context menu to set the data breakpoint.

    Data breakpoints will be disabled when the debugged application exits, as it
    is unlikely that the used addresses will stay the same at the next application
    launch. If you really want a data breakpoint to be active again, re-enable
    it manually.

    \sa {Debug}{How To: Debug}, {Debugging}, {Debuggers},
    {Setting breakpoints}
*/

/*!
    \page creator-locals-view.html
    \previouspage creator-reference.html

    \ingroup creator-reference-debugger

    \title Local variables and function parameters

    \brief Inspect local variables and function parameters.

    The \uicontrol {Locals} view consists of the \uicontrol Locals pane and the
    \uicontrol {Return Value} pane (hidden when empty).

    \image {qtcreator-locals.png} {Locals view}

    Whenever an application stops under the control of the debugger, it retrieves
    information about the topmost stack frame and displays it in the
    \uicontrol {Locals} view. The \uicontrol Locals pane shows
    information about parameters of the function in that frame as well as the
    local variables. If the last operation in the debugger was returning from a
    function after selecting \key {Shift+F11}, the \uicontrol {Return Value}
    pane displays the value returned by the function.

    You can expand the view contents to check that your application sets a
    local value correctly.

    \section1 Locals view actions

    Right-click the \uicontrol Locals view to select the following actions:

    //! [0]
    \list
        \li Add and remove expression evaluators
        \li \l{Change value display format}
        \li Expand and collapse view contents
        \li Copy view contents or expression values to the clipboard
        \li Open view contents in an editor
        \li Open memory editor
        \li Set data breakpoints
        \li Use \l{Debugging Helpers}{debugging helpers}
        \li Show and hide tooltips in the view when debugging
        \li Dereference pointers automatically
        \li Sort members of classes and structs alphabetically
        \li Use dynamic object type for display
        \li Set debugger preferences
    \endlist
    //! [0]

    \section1 Selecting object type for display

    When using GDB, you can specify whether the dynamic or the static type of
    objects will be displayed. Select \uicontrol {Use dynamic object type for
    display} in the context menu. Keep in mind that choosing the dynamic type
    might be slower.

    \sa {Debug}{How to: Debug}, {Debugging}, {Debuggers}
*/

/*!
    \page creator-expressions-view.html
    \previouspage creator-reference.html

    \ingroup creator-reference-debugger

    \title Evaluating expressions

    \brief Compute values of arithmetic expressions or function calls.

    To access global data that is not visible in the
    \l {Local variables and function parameters}{Locals} view or to compute
    values of arithmetic expressions or function calls, use
    expression evaluators in the \uicontrol Expressions view.

    For example, if you define
    \c {static int staticVar = 42;} in a source file and then add \c staticVar
    as an evaluated expression, you should see \e 42 in the view when the
    debugger stops in the source file.

    You can also use Expression Evaluators as shortcuts to items that are
    nested deeply in the locals tree.

    \image {qtcreator-debugger-expressions.webp} {Expressions view}

    \section1 Adding expression evaluators

    To add expression evaluators, drag an expression from the code editor
    to the \uicontrol Expressions view.

    You can also:

    \list
        \li Double-click in the \uicontrol {Expressions} or \uicontrol {Locals}
            view.
        \li Select \uicontrol {Add New Expression Evaluator} from the context
            menu.
    \endlist

    Enter the expression in the \uicontrol {New Evaluated Expression} dialog:

    \image {qtcreator-debugger-new-evaluated-expression.webp} {New Evaluated Expression dialog}

    \omit
    ## Visible in the context menu, but does not currently work.

    To insert widgets into expression evaluators, select a
    widget in the debugged application and then select
    \uicontrol {Select Widget to Add into Expression Evaluator}
    in the context menu.
    \endomit

    The set of evaluated expressions is saved in your session.

    Expression evaluators are re-evaluated whenever the current frame changes.
    The functions used in the expressions are called each time, even if
    they have side-effects.

    \note Evaluating expressions is slow, so remove expression evaluators after
    use.

    \section1 JavaScript expressions

    The QML debugger can evaluate JavaScript expressions.

    \section1 C and C++ expressions

    CDB, GDB, and LLDB support the evaluation of simple C and C++ expressions,
    such as arithmetic expressions made of simple values and pointers.

    Depending on the backend and concrete location, some function calls
    can be evaluated. CDB is the most limited backend in this respect.

    \section2 Function calls

    Functions can be called only if they are actually compiled into the debugged
    executable or a library used by the executable. Inlined
    functions such as most \c{operator[]} implementations of standard containers
    are typically \e{not} available.

    \note When an expression has a function call, anything can happen, including
    corruption of the application's state, or using the application's permission
    to perform arbitrary actions.

    \section2 Ranged syntax

    When using GDB or LLDB as backend, you can use a special ranged syntax to
    display multiple values with one expression. A sub-expression of form
    \c{foo[a..b]} is split into a sequence of individually evaluated expressions
    \c{foo[a], ..., foo[b]}.

    \section2 Compound variables

    You can expand compound variables of struct or class type to show their
    members. As you also see the variable value and type, you can examine and
    traverse the low-level layout of object data.

    \section2 Optimized builds

    GDB and LLDB, and therefore \QC's debugger, also work for optimized
    builds on Linux and \macos. Optimization can lead to re-ordering
    of instructions or removal of some local variables, causing the
    \uicontrol {Locals} and \uicontrol {Expressions} views to show
    unexpected data.

    \section2 GCC

    The debug information from GCC does not include enough
    information about the time when a variable is initialized.
    Therefore, \QC can not tell whether the contents of a local
    variable are \e {real data} or \e {initial noise}. If a QObject
    appears uninitialized, its value is reported as
    \uicontrol {not in scope}. Not all uninitialized objects,
    however, can be recognized as such.

    \section1 Expressions view actions

    Right-click the \uicontrol Expressions view to select the following actions:

    \include creator-debug-views.qdoc 0

    \sa {Debug}{How to: Debug}, {Debugging}, {Debuggers}
*/
