LCOV - code coverage report
Current view: top level - gjs - stack.cpp (source / functions) Coverage Total Hit
Test: gjs- Code Coverage Lines: 54.5 % 33 18
Test Date: 2024-04-20 17:42:51 Functions: 33.3 % 3 1
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 50.0 % 10 5

             Branch data     Line data    Source code
       1                 :             : /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
       2                 :             : // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
       3                 :             : // SPDX-FileCopyrightText: 2009 Red Hat, Inc.
       4                 :             : 
       5                 :             : #include <config.h>
       6                 :             : 
       7                 :             : #include <stdio.h>  // for stderr
       8                 :             : 
       9                 :             : #include <sstream>
      10                 :             : #include <string>
      11                 :             : 
      12                 :             : #include <glib-object.h>
      13                 :             : #include <glib.h>
      14                 :             : 
      15                 :             : #include <js/Printer.h>
      16                 :             : #include <js/TypeDecls.h>
      17                 :             : #include <js/Utility.h>  // for UniqueChars
      18                 :             : #include <js/friend/DumpFunctions.h>
      19                 :             : 
      20                 :             : #include "gjs/context-private.h"
      21                 :             : #include "gjs/context.h"
      22                 :             : #include "gjs/jsapi-util.h"
      23                 :             : 
      24                 :             : void
      25                 :           0 : gjs_context_print_stack_stderr(GjsContext *context)
      26                 :             : {
      27                 :           0 :     JSContext *cx = (JSContext*) gjs_context_get_native_context(context);
      28                 :             : 
      29                 :           0 :     g_printerr("== Stack trace for context %p ==\n", context);
      30                 :           0 :     js::DumpBacktrace(cx, stderr);
      31                 :           0 : }
      32                 :             : 
      33                 :             : void
      34                 :           0 : gjs_dumpstack(void)
      35                 :             : {
      36                 :           0 :     GjsSmartPointer<GList> contexts = gjs_context_get_all();
      37                 :             :     GList *iter;
      38                 :             : 
      39         [ #  # ]:           0 :     for (iter = contexts; iter; iter = iter->next) {
      40                 :           0 :         GjsAutoUnref<GjsContext> context(GJS_CONTEXT(iter->data));
      41                 :           0 :         gjs_context_print_stack_stderr(context);
      42                 :           0 :     }
      43                 :           0 : }
      44                 :             : 
      45                 :             : std::string
      46                 :          44 : gjs_dumpstack_string() {
      47                 :          44 :     std::string out;
      48                 :          44 :     std::ostringstream all_traces;
      49                 :             : 
      50                 :          44 :     GjsSmartPointer<GList> contexts = gjs_context_get_all();
      51                 :          44 :     js::Sprinter printer;
      52                 :             :     GList *iter;
      53                 :             : 
      54         [ +  + ]:          88 :     for (iter = contexts; iter; iter = iter->next) {
      55                 :          44 :         GjsAutoUnref<GjsContext> context(GJS_CONTEXT(iter->data));
      56         [ -  + ]:          44 :         if (!printer.init()) {
      57                 :           0 :             all_traces << "No stack trace for context " << context.get()
      58                 :           0 :                        << ": out of memory\n\n";
      59                 :           0 :             break;
      60                 :             :         }
      61                 :             :         auto* cx =
      62                 :          44 :             static_cast<JSContext*>(gjs_context_get_native_context(context));
      63                 :          44 :         js::DumpBacktrace(cx, printer);
      64                 :          44 :         JS::UniqueChars trace = printer.release();
      65                 :          44 :         all_traces << "== Stack trace for context " << context.get() << " ==\n"
      66                 :          44 :                    << trace.get() << "\n";
      67         [ +  - ]:          44 :     }
      68                 :          44 :     out = all_traces.str();
      69         [ +  - ]:          44 :     out.resize(MAX(out.size() - 2, 0));
      70                 :             : 
      71                 :          44 :     return out;
      72                 :          44 : }
        

Generated by: LCOV version 2.0-1