Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No translation units found #337

Open
ppetrov75 opened this issue Nov 14, 2024 · 39 comments
Open

No translation units found #337

ppetrov75 opened this issue Nov 14, 2024 · 39 comments

Comments

@ppetrov75
Copy link

Hello.

I just started to use clang-uml and maybe do not right.

I use simple .clang-uml:

compilation_database_dir: .
output_directory: diagrams
diagrams:
  class_diagram:
    type: class
    glob:
      - src/dir/*.cpp

  sequence_diagram:
    type: sequence
    glob:
      - src/dir1/*.cpp
      - src/dir/Main.cpp
    exclude:
      namespaces:
        - std
    start_from:
      - function: "main(int,const char**)"

output of call clang-uml -vvv :

...
[debug] [tid 263321] [generators.cc:61] Found 2 translation units for diagram class_diagram
...
[debug] [tid 263321] [generators.cc:61] Found 3 translation units for diagram sequence_diagram
[debug] [tid 263321] [generators.cc:241] Found 2 valid translation units for diagram class_diagram
[error] [tid 263321] [generators.cc:254] Diagram class_diagram generation failed: no translation units found. Please make sure that your 'glob' patterns match at least 1 file in 'compile_commands.json'.
[debug] [tid 263321] [generators.cc:241] Found 3 valid translation units for diagram sequence_diagram
[error] [tid 263321] [generators.cc:254] Diagram sequence_diagram generation failed: no translation units found. Please make sure that your 'glob' patterns match at least 1 file in 'compile_commands.json'.

I see info about files searched by glob at compile_commands.json . But diagrams are not generated.
If I use parameter path instead glob then number of translation much bigger but result is same.

I would appreciate if you point me right way to get build diagrams.

Thank you.

@bkryza
Copy link
Owner

bkryza commented Nov 14, 2024

@ppetrov75 Can you share the contents of your compile_commands.json or if it's too big just a few entries containing the files files in src/dir?

@ppetrov75
Copy link
Author

ppetrov75 commented Nov 14, 2024

Thank you.

I shortened a little, removed many includes.

    {
        "command": "/usr/bin/clang -I/ -std=gnu++20 -Wall -Wextra -Werror -ggdb -O3 -DNDEBUG -isystem dir1 -isystem dir2  -iquote external/yaml-cpp  -x c++ -c dir/file.cpp",
        "directory": "/path_from_root_to_dir",
        "file": "dir/file.cpp"
    },

@bkryza
Copy link
Owner

bkryza commented Nov 14, 2024

@ppetrov75 Ok, the problem is that your build generator created the compile commands with files relative to src directory, so clang-uml cannot match them to patterns src/dir/*.cpp.

Either change the patterns in clang-uml to dir/*.cpp and move .clang-uml to src directory, or add the following option at the top of the config file:

relative_to: src

@ppetrov75
Copy link
Author

sorry I did mistake
correct compile_commands.json

    {
        "command": "/usr/bin/clang -I/ -std=gnu++20 -Wall -Wextra -Werror -ggdb -O3 -DNDEBUG -isystem dir1 -isystem dir2  -iquote external/yaml-cpp  -x c++ -c src/dir/file.cpp",
        "directory": "/path_from_root_to_src",
        "file": "src/dir/file.cpp"
    },

I checked this file in the clang-uml project:

{
  "directory": "/home/user/work/UML/clang-uml/debug/src",
  "command": "/usr/bin/c++  -I/usr/lib/llvm-16/include -I/home/user/work/UML/clang-uml/include -I/home/user/work/UML/clang-uml/src/uml -I/home/user/work/UML/clang-uml/thirdparty -I/home/user/work/UML/clang-uml/src -I/home/user/work/UML/clang-uml/debug/src/version -isystem /usr/include/c++/13 -isystem /usr/include/x86_64-linux-gnu/c++/13 -isystem /usr/include/c++/13/backward -isystem /usr/lib/gcc/x86_64-linux-gnu/13/include -isystem /usr/local/include -isystem /usr/include/x86_64-linux-gnu -isystem /usr/include -g -std=c++17 -Werror -Wall -Wextra -Wno-unused-parameter -Wno-deprecated-declarations -Wno-dangling-reference -o CMakeFiles/clang-umllib.dir/class_diagram/generators/json/class_diagram_generator.cc.o -c /home/user/work/UML/clang-uml/src/class_diagram/generators/json/class_diagram_generator.cc",
  "file": "/home/user/work/UML/clang-uml/src/class_diagram/generators/json/class_diagram_generator.cc",
  "output": "src/CMakeFiles/clang-umllib.dir/class_diagram/generators/json/class_diagram_generator.cc.o"
},

here path to file is full.
So I modificated "file": "src/dir/file.cpp" to full path "/path_from_root_to_src/src/dir/file.cpp"
Is there option to fix it without modification to full path ?

now:

In file included from /usr/bin/../include/c++/v1/optional:186:
In file included from /usr/bin/../include/c++/v1/__functional/hash.h:16:
In file included from /usr/bin/../include/c++/v1/__tuple/sfinae_helpers.h:14:
In file included from /usr/bin/../include/c++/v1/__tuple/make_tuple_types.h:15:
In file included from /usr/bin/../include/c++/v1/__tuple/tuple_element.h:13:
/usr/bin/../include/c++/v1/__tuple/tuple_indices.h:26:11: error: reference to unresolved using declaration
   26 | template <size_t _Ep, size_t _Sp = 0>
      |           ^
/usr/bin/../include/c++/v1/cstddef:61:1: note: using declaration annotated with 'using_if_exists' here
   61 | using ::size_t _LIBCPP_USING_IF_EXISTS;
      | ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]

option exclude doesn't help

    exclude:
      namespaces:
        - std

Thank you

@bkryza
Copy link
Owner

bkryza commented Nov 14, 2024

@ppetrov75 Relative paths definitely used to work, but maybe there is a regression - I'll check.

As to your second error, those kinds of errors (assuming your code actually compiles) are relative to invalid or missing paths to system headers. The easiest option to overcome them is to add the following option to clang-uml command line --query-driver . or --query-driver <PATH_TO_YOUR_C++_COMPILER>. However in your case the first option --query-driver . will not work because for some reason your compile_commands.json command uses clang instead of clang++: "command": "/usr/bin/clang ..., so you would need to adjust it to /usr/bin/clang++.

Out of curiosity, what tool are you using to generate compile_commands.json?

@ppetrov75
Copy link
Author

I use grailbio/bazel-compilation-database . It's old and there recommended to switch on hedronvision/bazel-compile-commands-extractor or bazel-stack-vscode-cc. I tried first and same problem, maybe required some time.

It started to work, I see class diagram now. I replaced clang on clang++, added full paths, and call with --query_command . . Which one helped I don't know. )

sequence diagram still not generated.

/common/generators/generators.h:283] Visiting source file: src/dir/Main.cpp
...
sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:669] Failed to find participant with main(int,const char**) for start_from condition

in Main.cpp:

int main(int argc, const char** argv)
{

Thank you!
will continue tomorrow

@bkryza
Copy link
Owner

bkryza commented Nov 14, 2024

@ppetrov75 Ok, so there is progress at least. In case of the sequence diagrams, you have to specify the start_from exactly as it is seen by clang-uml, not necessarily as it is written in the code. The most certain way to get this right, is to call clang-uml with the following options -n sequence_diagram --print-from and grep the output with the expected function name (in your case just grep main) and then copy the value to the start_from condition...

@ppetrov75
Copy link
Author

ppetrov75 commented Nov 15, 2024

Good day.
I'm trying to use sequence mode:

  sequence_diagram:
    type: sequence
    glob:
      - src/dir1/A.cpp
      - src/dir2/Main.cpp
    
    using_namespace: ns
    include: # if use this include main() is not found, so it's moved to namespace ns
      namespaces:
        - ns
    inline_lambda_messages: true
    from:
      # - function: "main(int, const char* argv[])"
      - function: "ns::main(int,const char **)"

code simply:

namespase ns {
int  main() {
    handling();
    A a;
    a.foo();

   main_end(); // marker for option "to:"
}
}

Problem is not shown call ctr class A, call of a.foo(); .
If I add in "from: ":

- function: "ns::A::A()"

Call ctr A is shown, but it's different entry point.
Is it because different translation unit or I not added some option?
1.
sd1

sd2

Thank you.

@bkryza
Copy link
Owner

bkryza commented Nov 15, 2024

@ppetrov75 I need more information to reproduce the problem. Can you share entire contents of src/dir1/A.cpp and src/dir2/Main.cpp (and any headers they include), the diagram generation will definitely not work based on the snipped you provided (main has no arguments).

@ppetrov75
Copy link
Author

.clang-uml:

  sequence_diagram:
    type: sequence
    glob:
      - src/dir1/A.cpp
      - src/dir2/Main.cpp
    
    using_namespace: ns
#    include:
#      namespaces:
#        - ns

    inline_lambda_messages: true
    generate_condition_statements: true
    generate_message_comments: true

    from:
      - function: "main(int,const char **)"
      # - function: "ns::A::A()"

Main.cpp:

#include "A.h"

static void handling(void) {}
static void main_end() {}

using namespace ns;

int main(int , const char** )
{
    handling();

    A a;
    a.foo();

    main_end();

    return 0;
}

A.h:

#pragma once

namespace ns
{
class A
{
public:
    A();
    void foo();
};
}

A.cpp:

#include "A.h"

namespace ns
{

A::A()
{
}

void A::foo(void)
{
}
}

diagram:
sd3

@ppetrov75
Copy link
Author

output with -vvv:

[debug] [tid 257907] [/home/clang-uml/src/config/yaml_decoders.cc:1089] Effective config file path is /home/user/work/.clang-uml
[info] [tid 257907] [/home/clang-uml/src/cli/cli_handler.cc:306] Loaded clang-uml config from .clang-uml
[info] [tid 257907] [/home/clang-uml/src/cli/cli_handler.cc:333] Loading compilation database from /home/user/work/ directory
[debug] [tid 257907] [/home/clang-uml/src/config/config.cc:355] Looking for translation units in /home/user/work
[debug] [tid 257907] [/home/clang-uml/src/config/config.cc:381] Searching glob path /home/user/work/src/dir1/A.cpp
[debug] [tid 257907] [/home/clang-uml/src/config/config.cc:381] Searching glob path /home/user/work/src/dir2/Main.cpp
[debug] [tid 257907] [/home/clang-uml/src/common/generators/generators.cc:61] Found 2 translation units for diagram sequence_diagram
[debug] [tid 257907] [/home/clang-uml/src/common/generators/generators.cc:241] Found 2 valid translation units for diagram sequence_diagram
[debug] [tid 257907] [/home/clang-uml/src/common/generators/generators.cc:263] Found 2 matching translation unit commands for diagram sequence_diagram
[info] [tid 257918] [/home/clang-uml/src/common/generators/generators.h:366] Generating diagram sequence_diagram
[debug] [tid 257918] [/home/clang-uml/src/common/generators/generators.h:373] Found translation units for diagram sequence_diagram: /home/user/work/src/dir1/A.cpp, /home/user/work/src/dir2/Main.cpp
[debug] [tid 257918] [/home/clang-uml/src/util/query_driver_output_extractor.cc:41] Executing query driver command: /usr/bin/clang++ -E -v -x c++ /dev/null 2>&1
[debug] [tid 257918] [/home/clang-uml/src/util/query_driver_output_extractor.cc:56] Extracted the following paths from compiler driver: /usr/include/dbus-1.0,/usr/lib/dbus-1.0/include,/usr/bin/../include/c++/v1,/usr/lib/clang/17/include,/usr/include
[debug] [tid 257918] [/home/clang-uml/src/common/generators/generators.h:283] Visiting source file: src/dir1/A.cpp
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:173] Visiting class declaration at src/dir1/A.h:5:1
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2131] Setting local element mapping 576 --> 5106305860160781827
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:206] Adding class participant ns::A with id 5106305860160781827
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/call_expression_context.cc:187] Setting current caller id to 5106305860160781827
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:85] Adding 'class' participant: ns::A, 5106305860160781827 []
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2735] Including method ns::A::A
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:401] Calling VisitCXXMethodDecl recursively for forward declaration
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2735] Including method ns::A::A
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:409] Visiting method ns::A::A in class ns::A [0x7f3c400f22b0]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2601] Getting method's class with local id 576
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2131] Setting local element mapping 662 --> 10172215697977537271
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2131] Setting local element mapping 881 --> 10172215697977537271
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:438] Set id 881 --> 10172215697977537271 for method name ns::A::A() [true]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/call_expression_context.cc:187] Setting current caller id to 10172215697977537271
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:85] Adding 'method' participant: ns::A::A(), 10172215697977537271 [A]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2735] Including method ns::A::foo
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:401] Calling VisitCXXMethodDecl recursively for forward declaration
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2735] Including method ns::A::foo
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:409] Visiting method ns::A::foo in class ns::A [0x7f3c400f22b0]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2601] Getting method's class with local id 576
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2131] Setting local element mapping 692 --> 1384446150650511929
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2131] Setting local element mapping 938 --> 1384446150650511929
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:438] Set id 938 --> 1384446150650511929 for method name ns::A::foo() [true]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/call_expression_context.cc:187] Setting current caller id to 1384446150650511929
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:85] Adding 'method' participant: ns::A::foo(), 1384446150650511929 [foo]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2735] Including method ns::A::A
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:409] Visiting method ns::A::A in class ns::A [0x7f3c400f22b0]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2601] Getting method's class with local id 576
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2131] Setting local element mapping 662 --> 10172215697977537271
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2131] Setting local element mapping 881 --> 10172215697977537271
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:438] Set id 881 --> 10172215697977537271 for method name ns::A::A() [true]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/call_expression_context.cc:187] Setting current caller id to 10172215697977537271
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2735] Including method ns::A::foo
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:409] Visiting method ns::A::foo in class ns::A [0x7f3c400f22b0]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2601] Getting method's class with local id 576
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2131] Setting local element mapping 692 --> 1384446150650511929
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2131] Setting local element mapping 938 --> 1384446150650511929
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:438] Set id 938 --> 1384446150650511929 for method name ns::A::foo() [true]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/call_expression_context.cc:187] Setting current caller id to 1384446150650511929
[debug] [tid 257918] [/home/clang-uml/src/util/query_driver_output_extractor.cc:41] Executing query driver command: /usr/bin/clang++ -E -v -x c++ /dev/null 2>&1
[debug] [tid 257918] [/home/clang-uml/src/util/query_driver_output_extractor.cc:56] Extracted the following paths from compiler driver: /usr/include/dbus-1.0,/usr/lib/dbus-1.0/include,/usr/bin/../include/c++/v1,/usr/lib/clang/17/include,/usr/include
[debug] [tid 257918] [/home/clang-uml/src/common/generators/generators.h:283] Visiting source file: src/dir2/Main.cpp
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:483] Visiting function declaration handling at src/dir2/Main.cpp:3:13
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/call_expression_context.cc:187] Setting current caller id to 2963991483338076281
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2131] Setting local element mapping 743 --> 2963991483338076281
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2131] Setting local element mapping 743 --> 2963991483338076281
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:85] Adding 'function' participant: handling(), 2963991483338076281 []
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:483] Visiting function declaration main_end at src/dir2/Main.cpp:4:13
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/call_expression_context.cc:187] Setting current caller id to 18026605205433578579
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2131] Setting local element mapping 784 --> 18026605205433578579
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2131] Setting local element mapping 784 --> 18026605205433578579
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:85] Adding 'function' participant: main_end(), 18026605205433578579 []
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:483] Visiting function declaration main at src/dir2/Main.cpp:8:5
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/call_expression_context.cc:187] Setting current caller id to 10203697914391728678
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2131] Setting local element mapping 883 --> 10203697914391728678
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2131] Setting local element mapping 883 --> 10203697914391728678
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:85] Adding 'function' participant: main(int,const char **), 10203697914391728678 []
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:721] Entering call expression at src/dir2/Main.cpp:10:5
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1361] Visiting call expression at src/dir2/Main.cpp:10:5 [caller_id = 10203697914391728678]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1497] Found call handling from 10203697914391728678 [10203697914391728678] to 2963991483338076281 [2963991483338076281] 
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:728] Leaving call expression at src/dir2/Main.cpp:10:5
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:823] Entering cxx construct call expression at src/dir2/Main.cpp:12:7
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:833] Leaving cxx construct call expression at src/dir2/Main.cpp:12:7
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:769] Entering member call expression at src/dir2/Main.cpp:13:5
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1361] Visiting call expression at src/dir2/Main.cpp:13:5 [caller_id = 10203697914391728678]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2714] Skipping call expression at src/dir2/Main.cpp:13:5
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1382] Skipping call expression due to filter at: src/dir2/Main.cpp:13:5
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:777] Leaving member call expression at src/dir2/Main.cpp:13:5
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:721] Entering call expression at src/dir2/Main.cpp:15:5
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1361] Visiting call expression at src/dir2/Main.cpp:15:5 [caller_id = 10203697914391728678]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1497] Found call main_end from 10203697914391728678 [10203697914391728678] to 18026605205433578579 [18026605205433578579] 
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:728] Leaving call expression at src/dir2/Main.cpp:15:5
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:523]  --- Participants ---
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:525] 1384446150650511929 - Participant 'method': id=1384446150650511929, name=ns::A::foo(), class_id=5106305860160781827
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:525] 2963991483338076281 - Participant 'function': id=2963991483338076281 name=handling()
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:525] 5106305860160781827 - Participant 'class': id=5106305860160781827 name=ns::A
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:525] 10172215697977537271 - Participant 'method': id=10172215697977537271, name=ns::A::A(), class_id=5106305860160781827
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:525] 10203697914391728678 - Participant 'function': id=10203697914391728678 name=main(int,const char **)
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:525] 18026605205433578579 - Participant 'function': id=18026605205433578579 name=main_end()
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:528]  --- Activities ---
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:533] Sequence id=10203697914391728678:
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:537]    Activity id=10203697914391728678, from=main(int,const char **):
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:561]        Message from=main(int,const char **), from_id=10203697914391728678, to=handling(), to_id=2963991483338076281, name=handling, type=call, comment=None
[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:561]        Message from=main(int,const char **), from_id=10203697914391728678, to=main_end(), to_id=18026605205433578579, name=main_end, type=call, comment=None
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:662] Found sequence diagram start point: 10203697914391728678
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:195] Generating message [10203697914391728678] --> [2963991483338076281]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:127] Generated call '' from main(int,const char **) [10203697914391728678] to handling() [2963991483338076281]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:213] Skipping activity 10203697914391728678 --> 2963991483338076281 - missing sequence 2963991483338076281
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:195] Generating message [10203697914391728678] --> [18026605205433578579]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:127] Generated call '' from main(int,const char **) [10203697914391728678] to main_end() [18026605205433578579]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:213] Skipping activity 10203697914391728678 --> 18026605205433578579 - missing sequence 18026605205433578579
[info] [tid 257918] [/home/clang-uml/src/common/generators/generators.cc:118] Written sequence_diagram diagram to /home/user/work/diagrams/sequence_diagram.puml

@bkryza
Copy link
Owner

bkryza commented Nov 15, 2024

@ppetrov75 This is very strange. I created a small CMake project using your exact files, I just added the CMakeLists.txt:

cmake_minimum_required(VERSION 3.15)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(Issue337 LANGUAGES CXX)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

add_executable(Main src/dir2/Main.cpp src/dir1/A.cpp)

and the output log I get at the end is:

[trace] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/model/diagram.cc:523]  --- Participants ---
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/model/diagram.cc:525] 1384446150650511929 - Participant 'method': id=1384446150650511929, name=ns::A::foo(), class_id=5106305860160781827
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/model/diagram.cc:525] 2963991483338076281 - Participant 'function': id=2963991483338076281 name=handling()
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/model/diagram.cc:525] 5106305860160781827 - Participant 'class': id=5106305860160781827 name=ns::A
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/model/diagram.cc:525] 10172215697977537271 - Participant 'method': id=10172215697977537271, name=ns::A::A(), class_id=5106305860160781827
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/model/diagram.cc:525] 10203697914391728678 - Participant 'function': id=10203697914391728678 name=main(int,const char **)
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/model/diagram.cc:525] 18026605205433578579 - Participant 'function': id=18026605205433578579 name=main_end()
[trace] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/model/diagram.cc:528]  --- Activities ---
[trace] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/model/diagram.cc:533] Sequence id=10203697914391728678:
[trace] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/model/diagram.cc:537]    Activity id=10203697914391728678, from=main(int,const char **):
[trace] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/model/diagram.cc:561]        Message from=main(int,const char **), from_id=10203697914391728678, to=handling(), to_id=2963991483338076281, name=handling, type=call, comment=None
[trace] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/model/diagram.cc:561]        Message from=main(int,const char **), from_id=10203697914391728678, to=ns::A::A(), to_id=10172215697977537271, name=ns::A::A, type=call, comment=None
[trace] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/model/diagram.cc:561]        Message from=main(int,const char **), from_id=10203697914391728678, to=ns::A::foo(), to_id=1384446150650511929, name=foo, type=call, comment=None
[trace] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/model/diagram.cc:561]        Message from=main(int,const char **), from_id=10203697914391728678, to=main_end(), to_id=18026605205433578579, name=main_end, type=call, comment=None
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:682] Found sequence diagram start point: 10203697914391728678
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:197] Generating message [10203697914391728678] --> [2963991483338076281]
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:129] Generated call '' from main(int,const char **) [10203697914391728678] to handling() [2963991483338076281]
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:215] Skipping activity 10203697914391728678 --> 2963991483338076281 - missing sequence 2963991483338076281
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:197] Generating message [10203697914391728678] --> [10172215697977537271]
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:129] Generated call 'A()' from main(int,const char **) [10203697914391728678] to ns::A::A() [10172215697977537271]
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:215] Skipping activity 10203697914391728678 --> 10172215697977537271 - missing sequence 10172215697977537271
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:197] Generating message [10203697914391728678] --> [1384446150650511929]
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:129] Generated call 'foo()' from main(int,const char **) [10203697914391728678] to ns::A::foo() [1384446150650511929]
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:215] Skipping activity 10203697914391728678 --> 1384446150650511929 - missing sequence 1384446150650511929
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:197] Generating message [10203697914391728678] --> [18026605205433578579]
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:129] Generated call '' from main(int,const char **) [10203697914391728678] to main_end() [18026605205433578579]
[debug] [tid 453951] [/home/bartek/devel/clang-uml/src/sequence_diagram/generators/plantuml/sequence_diagram_generator.cc:215] Skipping activity 10203697914391728678 --> 18026605205433578579 - missing sequence 18026605205433578579
[info] [tid 453951] [/home/bartek/devel/clang-uml/src/common/generators/generators.cc:118] Written sequence_diagram diagram to /home/bartek/devel/clang-uml-issues/337/sequence_diagram.puml

and the diagram:

@startuml
participant "main(int,const char **)" as C_0010203697914391728678
activate C_0010203697914391728678
participant "handling()" as C_0002963991483338076281
C_0010203697914391728678 -> C_0002963991483338076281 : 
activate C_0002963991483338076281
deactivate C_0002963991483338076281
participant "A" as C_0005106305860160781827
C_0010203697914391728678 -> C_0005106305860160781827 : A()
activate C_0005106305860160781827
deactivate C_0005106305860160781827
C_0010203697914391728678 -> C_0005106305860160781827 : foo()
activate C_0005106305860160781827
deactivate C_0005106305860160781827
participant "main_end()" as C_0018026605205433578579
C_0010203697914391728678 -> C_0018026605205433578579 : 
activate C_0018026605205433578579
deactivate C_0018026605205433578579
deactivate C_0010203697914391728678

'Generated with clang-uml, version 0.5.5-37-g7e28757
'LLVM version Ubuntu clang version 18.1.8 (++20240731025043+3b5b5c1ec4a3-1~exp1~20240731145144.92)
@enduml

From the log you've sent me it seems on your side, Clang is not visiting the a.foo() call expression. Can you also paste the output of clang-uml --version?

@ppetrov75
Copy link
Author

ppetrov75 commented Nov 15, 2024

I built on last master: cb03149

clang-uml 0.5.5-35-gcb03149
Copyright (C) 2021-2024 Bartek Kryza <[email protected]>
Linux x86_64 5.15.0-78-generic
Built against LLVM/Clang libraries version: 17.0.4
Using LLVM/Clang libraries version: clang version 17.0.4 (https://github.com/llvm/llvm-project 309d55140c46384b6de7a7573206cbeba3f7077f)

maybe built not right?

mkdir dir 
cd dir
cmake ..
make
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: /usr/bin/git (found version "2.42.0") 
-- clang-uml version: 0.5.5-35-gcb03149
-- Checking for LLVM and Clang...
-- Performing Test HAVE_FFI_CALL
-- Performing Test HAVE_FFI_CALL - Success
-- Found FFI: /usr/lib/libffi.so  
-- Looking for histedit.h
-- Looking for histedit.h - found
-- Found LibEdit: /usr/include (found version "2.11") 
-- Found ZLIB: /usr/lib/libz.so (found version "1.3")  
-- Found zstd: /usr/lib/libzstd.so  
-- Found LibXml2: /usr/lib/libxml2.so (found version "2.12.5") 
-- Linker detection: GNU ld
-- Found LLVM 17.0.4
-- Using LLVMConfig.cmake from: /usr/lib/cmake/llvm
-- LLVM library dir: /usr/lib
-- Found LibTooling libraries: clang-cpp;LLVM
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Checking for yaml-cpp...
-- Found yaml-cpp at /home/user/work/UML/include
-- Disabling backward-cpp
-- Disabling Objective-C test cases
-- Disabling C++ modules test cases
-- Disabling CUDA test cases
-- Enabling C++20 test cases
-- Configuring done (0.9s)
-- Generating done (0.1s)

@bkryza
Copy link
Owner

bkryza commented Nov 15, 2024

@ppetrov75 clang-uml version is fine. I've looked at your logs more carefully, and I see that the call expression to foo() is rejected by the diagram filters:

[trace] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1361] Visiting call expression at src/dir2/Main.cpp:13:5 [caller_id = 10203697914391728678]
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2714] Skipping call expression at src/dir2/Main.cpp:13:5
[debug] [tid 257918] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1382] Skipping call expression due to filter at: src/dir2/Main.cpp:13:5

But that is impossible with the .clang-uml configuration file you pasted above. Can you paste the exact contents of your .clang-uml file (make sure you don't have a working copy in your editor which is not yet saved to disk for instance?)...

@ppetrov75
Copy link
Author

Good day.

I tried on small project with cmake. The tool works fine:
tree:

src/Main.cpp

src/dir1:
A.cpp  A.h

src/dir2:
B.cpp  B.h

config:

compilation_database_dir: debug
output_directory: diagrams
diagrams:
  sequence_diagram:
    type: sequence
    glob:
      # - A.cpp
      # - B.cpp
      - Main.cpp
    from:
      - function: "main(int,const char **)"

it's not required even include all files, additional includes namespaces etc:

compilation_database_dir: debug
output_directory: diagrams
diagrams:
  sequence_diagram:
    type: sequence
    glob:
      # - A.cpp
      # - B.cpp
      - Main.cpp
    from:
      - function: "main(int,const char **)"

it builds full seq diagram:
diagram1

Regarding real project.
May be you could add additional traces in the project for extend diagnostic and I build, try on it?
We see "Including method ns::A::foo" and it's "Skipping call expression at src/dir2/Main.cpp:13:5" . It's not shown call ctr class A too.
VSCode works fine with current compile_commands.json I can move between symbols by F12 and etc.
I modificate path to file otherwise clang-uml can't find unit. VSCode works with short path too. Command /usr/bin/clang is called with option "-x c++" but I can change call on clang++ for certainty.

I tried to build sequence diagram inside class. It doesn't build sequences for different namespaces, classes or even maybe for other files. Maybe some fix with not strict filtering rules will help. )

Thank you.

@bkryza
Copy link
Owner

bkryza commented Nov 16, 2024

@ppetrov75 I've created a branch issue-337 which should log which filter rejected each diagram element, just add -vvv and grep for rejected by and your method or class name, e.g.: clang-uml -vvv | grep "rejected by" | grep foo

If you still can't figure out the issue, please paste also the output of clang-uml --dump-config which will print you entire config including default values as seen by clang-uml...

@bkryza
Copy link
Owner

bkryza commented Nov 17, 2024

@ppetrov75 Also, I've just fixed a small regression I found today that impacted filtering sequence diagrams using paths filter - so please also try with the latest master maybe it was related to your issue...

@ppetrov75
Copy link
Author

Hello.

I tried clang-uml based on issue-337. I didn't find any "rejected" message in out like "... rejected by namespace_filter" just "Skipping call expression at".
It didn't work on last master as well.

I tried to place files in one directory, corrected paths in compile_commands.json and it started to work (I didn't understand yet it took all dependencies or not ).

compile_commands.json and sources are input data for processing clang-uml. No more dependencies? Then it looks there are some problem with compile_commands.json ? I checked there all paths to files are correct. It didn't work before probably because paths were relative, I changed on full. No more idea. )

it's part of compile_commands.json for short project:

[
{
  "directory": "/home/user/prj/debug",
  "command": "/usr/bin/clang++   -std=gnu++20 -o CMakeFiles/seq_diagram.dir/src/Main.cpp.o -c /home/user/prj/src/Main.cpp",
  "file": "/home/user/prj/src/Main.cpp",
  "output": "CMakeFiles/seq_diagram.dir/src/Main.cpp.o"
},
{
  "directory": "/home/user/prj/debug",
  "command": "/usr/bin/clang++   -std=gnu++20 -o CMakeFiles/seq_diagram.dir/src/dir1/A.cpp.o -c /home/user/prj/src/dir1/A.cpp",
  "file": "/home/user/prj/src/dir1/A.cpp",
  "output": "CMakeFiles/seq_diagram.dir/src/dir1/A.cpp.o"
},

If I change here paths on relative it doesn't find files.
I include in glob only Main.cpp, but data from A.cpp is found. And no some additional options like -I, -i paths in "command".

Thank you.

@bkryza
Copy link
Owner

bkryza commented Nov 18, 2024

@ppetrov75 Ok, just to be sure, can you also try on the latest master from yesterday evening, there will be no extract logs from issue-337 - but I've fixed a small bug with paths filter.

If it doesn't help, please paste the output of clang-uml --dump-config.

@ppetrov75
Copy link
Author

Yes. I tried latest master, issue-337 and rebased issue337 on the latest master.
I'll do tomorrow.
Thank you.

@bkryza
Copy link
Owner

bkryza commented Nov 18, 2024

@ppetrov75 I don't have any more ideas really, so I created a repository https://github.com/bkryza/issue337, with your example and your compile_commands.json (only adjusted global paths) please clone it, adjust the global paths in debug/compile_commands.json to wherever it is on your local file system and run clang-uml - on my side it works fine:

~/devel/clang-uml/debug/src/clang-uml -n sequence_diagram
[info] [tid 1929778] [/home/bartek/devel/clang-uml/src/cli/cli_handler.cc:306] Loaded clang-uml config from .clang-uml
[info] [tid 1929778] [/home/bartek/devel/clang-uml/src/cli/cli_handler.cc:334] Loading compilation database from /home/bartek/devel/clang-uml-issues/337/test/debug directory
[info] [tid 1929789] [/home/bartek/devel/clang-uml/src/common/generators/generators.h:367] Generating diagram sequence_diagram
[info] [tid 1929789] [/home/bartek/devel/clang-uml/src/common/generators/clang_tool.cc:161] Processing diagram 'sequence_diagram' translation unit: /home/bartek/devel/clang-uml-issues/337/test/src/dir1/A.cpp
[info] [tid 1929789] [/home/bartek/devel/clang-uml/src/common/generators/clang_tool.cc:161] Processing diagram 'sequence_diagram' translation unit: /home/bartek/devel/clang-uml-issues/337/test/src/Main.cpp
[info] [tid 1929789] [/home/bartek/devel/clang-uml/src/common/generators/generators.cc:118] Written sequence_diagram diagram to /home/bartek/devel/clang-uml-issues/337/test/sequence_diagram.puml
❯ cat sequence_diagram.puml
@startuml
participant "main(int,const char **)" as C_0010203697914391728678
activate C_0010203697914391728678
participant "handling()" as C_0002963991483338076281
C_0010203697914391728678 -> C_0002963991483338076281 : 
activate C_0002963991483338076281
deactivate C_0002963991483338076281
participant "A" as C_0005106305860160781827
C_0010203697914391728678 -> C_0005106305860160781827 : A()
activate C_0005106305860160781827
deactivate C_0005106305860160781827
C_0010203697914391728678 -> C_0005106305860160781827 : foo()
activate C_0005106305860160781827
deactivate C_0005106305860160781827
participant "main_end()" as C_0018026605205433578579
C_0010203697914391728678 -> C_0018026605205433578579 : 
activate C_0018026605205433578579
deactivate C_0018026605205433578579
deactivate C_0010203697914391728678

'Generated with clang-uml, version 0.5.5-39-g9d86ae1
'LLVM version Ubuntu clang version 18.1.8 (++20240731025043+3b5b5c1ec4a3-1~exp1~20240731145144.92)
@enduml

If this doesn't work for you - the only idea I have left is that there something wrong with your LLVM/Clang installation - are you able to install/build another version of LLVM on your machine?

@ppetrov75
Copy link
Author

ppetrov75 commented Nov 19, 2024

Good day.

Sorry. It's not related to issue question.
Is it possible to config placing objects in several rows? Aggregations are placed in one row and picture is very wide.
Screenshot from 2024-11-19 16-40-39

Thank you.

@bkryza
Copy link
Owner

bkryza commented Nov 19, 2024

@ppetrov75 In theory yes, but you would have to specify the layout constraint for every pair of classes like so:

    layout:
      ClassA:
        - up: ClassB

not really practical in your case, but in PlantUML you change the orientation of the layout to vertical, try adding the following plantuml directive to your diagram config:

diagrams:
  mydiagram:
    type: class
    ...
    plantuml:
      before:
        - left to right direction

@ppetrov75
Copy link
Author

ppetrov75 commented Nov 19, 2024

Thx

Now looks much better

Screenshot from 2024-11-19 17-10-20

Is it possible to hide links to aggregated types?

@bkryza
Copy link
Owner

bkryza commented Nov 19, 2024

@ppetrov75 Not sure what you mean by aggregated types specifically, but checkout the filters documentation here and also some of the test cases: t00040 or t00041.

@ppetrov75
Copy link
Author

Hello.

some details:
there are "Skipping call" like:

Skipping call expression at file.cpp:N:M <Spelling=/usr/lib/clang/17/include/stdarg.h:33:29>
Skipping call expression at file.cpp:N:M <Spelling=/usr/lib/clang/17/include/stdarg.h:35:29>

cat /usr/lib/clang/17/include/stdarg.h:

/*===---- stdarg.h - Variable argument handling ----------------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

#ifndef __STDARG_H

#ifndef __GNUC_VA_LIST
#define __GNUC_VA_LIST
typedef __builtin_va_list __gnuc_va_list;
#endif

#ifdef __need___va_list
#undef __need___va_list
#else
#define __STDARG_H
#ifndef _VA_LIST
typedef __builtin_va_list va_list;
#define _VA_LIST
#endif

/* FIXME: This is using the placeholder dates Clang produces for these macros
  in C2x mode; switch to the correct values once they've been published. */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L
/* C2x does not require the second parameter for va_start. */
#define va_start(ap, ...) __builtin_va_start(ap, 0)
#else
/* Versions before C2x do require the second parameter. */
#define va_start(ap, param) __builtin_va_start(ap, param)
#endif
#define va_end(ap)          __builtin_va_end(ap)
#define va_arg(ap, type)    __builtin_va_arg(ap, type)

/* GCC always defines __va_copy, but does not define va_copy unless in c99 mode
* or -ansi is not specified, since it was not part of C90.
*/
#define __va_copy(d,s) __builtin_va_copy(d,s)

#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) ||              \
   (defined(__cplusplus) && __cplusplus >= 201103L) ||                        \
   !defined(__STRICT_ANSI__)
#define va_copy(dest, src)  __builtin_va_copy(dest, src)
#endif

#endif /* __STDARG_H */

#endif /* not __STDARG_H */

The same problem with another external library. As I understood there is problem with spelling some method and It cancel call completely.

Is it possible to mask problem calls in config ?

Thank you.

@bkryza
Copy link
Owner

bkryza commented Nov 21, 2024

@ppetrov75 The log "Skipping call expression at" is fine in general, it means that according to the diagram filters you don't want that call in your diagram (or at least it should be). Can you share the config for this diagram, the line of code at file.cpp:N where a call is skipped that shouldn't be and entire log line (the log line should contain the file and line location in clang-uml which generated the log).

@ppetrov75
Copy link
Author

ppetrov75 commented Nov 21, 2024

Forgot to write after "Skipping call expression at" usually "Skipping call expression due to filter at" with same message after "at:"

config:

type: sequence
inline_lambda_messages: true
generate_return_types: true
generate_condition_statements: true
glob:
  - file.cpp
  - file1.cpp

from:
  - function: "someFunction()"  # from file.cpp

in file1.cpp:N:

va_end(args);

some kind of https://en.cppreference.com/w/cpp/utility/variadic/va_start

@ppetrov75 ppetrov75 reopened this Nov 21, 2024
@bkryza
Copy link
Owner

bkryza commented Nov 21, 2024

@ppetrov75 Ok, the problem is that you have no filters, i.e. this will try to include all calls. The easiest way to limit your diagram to calls within your codebase, just add:

  include:
    paths:
      - .

@ppetrov75
Copy link
Author

Sorry. It didn't help.

i tried on small project:

output_directory: diagrams
diagrams:
  sequence_diagram:
    type: sequence
    glob:
      - src/dir1/A.cpp
      - src/dir2/B.cpp
      - src/Main.cpp
    from:
      - function: "ns::func1()"
    include:
      paths:
        - .
    exclude:
      namespaces:
        - std
      paths:
        - /usr

src

#pragma once

namespace ns
{
    void func1();
}
***
#pragma once

namespace ns1::ns2
{
    void func2();
}
***
#include "A.h"
#include "dir2/B.h"

namespace ns
{

    void func1()
    {
        ns1::ns2::func2();

    }
}
***
 #include "B.h"
#include <cstdarg>

namespace ns1::ns2 {

int add_nums(int count...) {
  int result = 0;
  std::va_list args;
  va_start(args, count);
  for (int i = 0; i < count; ++i)
    result += va_arg(args, int);
  va_end(args);
  return result;
}

void func2() { auto n = add_nums(1, 2, 3, 4, 5); }

} // namespace ns1::ns2

it looks it tries to find inside _builtin_va*:

[debug] [tid 360896] [/home/clang-uml/src/common/generators/generators.h:283] Visiting source file: /home/tmp/prj/src/dir2/B.cpp
[debug] [tid 360896] [/home/clang-uml/src/sequence_diagram/visitor/call_expression_context.cc:187] Setting current caller id to 3072415738879189178
[debug] [tid 360896] [/home/clang-uml/src/sequence_diagram/visitor/call_expression_context.cc:187] Setting current caller id to 11714123522952758874
[debug] [tid 360896] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:85] Adding 'function' participant: ns1::ns2::add_nums(int), 11714123522952758874 []
[debug] [tid 360896] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2738] Including method __va_list_tag::__va_list_tag
[debug] [tid 360896] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1669] Constructor '__va_list_tag' call expression to 1097 at /home/tmp/prj/src/dir2/B.cpp:8:16
[debug] [tid 360896] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1582] Found constructor call __va_list_tag::__va_list_tag from 11714123522952758874 [11714123522952758874] to 1097 [1097] 
[debug] [tid 360896] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2738] Including method __va_list_tag::__va_list_tag
[debug] [tid 360896] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1669] Constructor '__va_list_tag' call expression to 1097 at /home/tmp/prj/src/dir2/B.cpp:8:16
[debug] [tid 360896] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1582] Found constructor call __va_list_tag::__va_list_tag from 11714123522952758874 [11714123522952758874] to 1097 [1097] 
[debug] [tid 360896] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1497] Found call __builtin_va_start from 11714123522952758874 [11714123522952758874] to 1385 [1385] 
[debug] [tid 360896] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1497] Found call __builtin_va_end from 11714123522952758874 [11714123522952758874] to 1588 [1588] 
[debug] [tid 360896] [/home/clang-uml/src/sequence_diagram/visitor/call_expression_context.cc:187] Setting current caller id to 3072415738879189178
[debug] [tid 360896] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1497] Found call ns1::ns2::add_nums from 3072415738879189178 [3072415738879189178] to 11714123522952758874 [11714123522952758874] 
[debug] [tid 360896] [/home/clang-uml/src/util/query_driver_output_extractor.cc:41] Executing query driver command: /usr/bin/clang++ -E -v -x c++ /dev/null 2>&1

@bkryza
Copy link
Owner

bkryza commented Nov 21, 2024

@ppetrov75 Ok, thanks for the example, I will try to reproduce on my side today evening.

@bkryza
Copy link
Owner

bkryza commented Nov 21, 2024

@ppetrov75 One more question - what was the error in that small example? No diagram generated? Missing call? If you got any diagram generated from the above example, can you paste it here?

@ppetrov75
Copy link
Author

ppetrov75 commented Nov 21, 2024

Diagram is generated. It's correct.

But in log:

[debug] [tid 361447] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1497] Found call __builtin_va_start from 11714123522952758874 [11714123522952758874] to 1385 [1385] 
[debug] [tid 361447] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1497] Found call __builtin_va_end from 11714123522952758874 [11714123522952758874] to 1588 [1588] 

It searchs __builtin_va_start, __builtin_va_end. If it is not found we have "Skipping call".
You said that it should be solved with "include: path: ./". I tried include it and exclude: std, /usr . And we see messages about searching _va*

@bkryza
Copy link
Owner

bkryza commented Nov 21, 2024

Ok, sorry I thought you weren't getting a valid diagram. I've tried to reproduce and I also get the correct diagram. The thing is that when analysing function which should be in the diagram (e.g. add_nums) I have to check every call expression in it to decide whether it should be followed or not, thus there is a log about __builtin_va_start and __builtin_va_end ( va_start and va_end are just macros resolving to them), and this cannot be skipped.

Now going back to your original problem, you mention that:

It searchs __builtin_va_start, __builtin_va_end. If it is not found we have...

If you have a call to these functions and they cannot be resolved by Clang in your header search path, then you should get an error and no diagram should be generated. Is that the case? If yes then you need to adjust your compile commands so that these functions are resolved properly. If not, can you explain the issue in more detail? What exactly is the problem in the end beside the logs? Preferably with example showing piece of code, the output diagram, and what is missing (or what is too much)?

@ppetrov75
Copy link
Author

ppetrov75 commented Nov 21, 2024

I don't know what is real problem why diagrams are not built in some cases. We see "Skipping call expression due to filter at" and points on some sequence of externals headers.
Is it possible to build sequence until it's possible and not skip previous tree ? I think on big projects with many external dependencies it would be good.
Thank you.

@bkryza
Copy link
Owner

bkryza commented Nov 21, 2024

@ppetrov75

Is it possible to build sequence until it's possible and not skip previous tree ?

I still don't understand what do you mean by possible here? If you have a case that a diagram is not generated at all, this means that there is an issue with your compilation database (e.g. include paths), and there is now way around this. clang-uml does not parse code itself, Clang parses the entire translation unit along with all headers that it includes, builds the Abstract Syntax Tree, and only then my code can traverse the AST and build the diagram. If Clang cannot build the AST (for instance because it cannot find some header with a function declaration), then you will not get the AST and clang-uml cannot even try to generate the diagram.

@ppetrov75
Copy link
Author

ppetrov75 commented Nov 21, 2024

It looks that it built some tree until "unknown" call.

There are some messages in log:

[debug] [tid 369883] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1497] Found call operator() from 1828292936365159546 [1828292936365159546] to 11148870 [11148870] 
[debug] [tid 369883] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:661] Found call  from 1828292936365159546 [1828292936365159546] to 2484913358082920003 [2484913358082920003]
[debug] [tid 369883] [/home/clang-uml/src/sequence_diagram/visitor/call_expression_context.cc:193] Setting current lambda caller id to 2484913358082920003

until:

[debug] [tid 369883] [/home/clang-uml/src/sequence_diagram/visitor/call_expression_context.cc:187] Setting current caller id to 2328796031965691674
[debug] [tid 369883] [/home/clang-uml/src/sequence_diagram/model/diagram.cc:85] Adding 'function' participant: someFunction(const char *), 2328796031965691674 []
[debug] [tid 369883] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2738] Including method __va_list_tag::__va_list_tag
[debug] [tid 369883] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1669] Constructor '__va_list_tag' call expression to 4224460 at /home/user/work/file.cpp:94:13
[debug] [tid 369883] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1582] Found constructor call __va_list_tag::__va_list_tag from 2328796031965691674 [2328796031965691674] to 4224460 [4224460] 
[debug] [tid 369883] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2738] Including method __va_list_tag::__va_list_tag
[debug] [tid 369883] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1669] Constructor '__va_list_tag' call expression to 4224460 at /home/user/work/file.cpp:94:13
[debug] [tid 369883] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1582] Found constructor call __va_list_tag::__va_list_tag from 2328796031965691674 [2328796031965691674] to 4224460 [4224460] 
[debug] [tid 369883] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:2717] Skipping call expression at /home/user/work/file.cpp:96:5 <Spelling=/usr/lib/clang/17/include/stdarg.h:33:29>
[debug] [tid 369883] [/home/clang-uml/src/sequence_diagram/visitor/translation_unit_visitor.cc:1382] Skipping call expression due to filter (VisitCallExpr) at: /home/user/work/file.cpp:96:5 <Spelling=/usr/lib/clang/17/include/stdarg.h:33:29>

finally diagram

@startuml
activate C_0017297503973676070717
deactivate C_0017297503973676070717

'Generated with clang-uml, version 0.5.5-39-g65924d8
'LLVM version clang version 17.0.4 (https://github.com/llvm/llvm-project 309d55140c46384b6de7a7573206cbeba3f7077f)
@enduml

@bkryza
Copy link
Owner

bkryza commented Nov 21, 2024

@ppetrov75 Ok this is interesting, but can you modify the above simple example with add_nums so that it fails in the same way? I found this SO discussion that I think discusses the same issue - I will try to investigate...

@bkryza
Copy link
Owner

bkryza commented Nov 21, 2024

@ppetrov75 I added a test case t20062 https://github.com/bkryza/clang-uml/blob/add-vaargs-test-case/docs/test_cases/t20062.md in branch add-vaargs-test-case, which replicates the same log as you can see, but for me it works fine, all calls are rendered. Can you check if this example works for you - if yes, then your issue is not related to __va_list_tag, but it's due to something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants