Giter Club home page Giter Club logo

Comments (11)

bkryza avatar bkryza commented on June 1, 2024

@bilboquet The problem here is that Stm32 is a 32-bit architecture so the cast is correct when compiling for Arm, but Clang parser used by clang-uml is not aware of that - can you share a subset of the compile_commands.json file - I'd like to see the compiler flags which are specified there...

clang-tidy probably works because it does check the Stm32 Cube headers

from clang-uml.

bilboquet avatar bilboquet commented on June 1, 2024

@bkryza thanks for your reply

The compile_commands.json is huge, so here is an extract extract.zip (the original file has many entries like this, I've also removed some line that are special to my project but that should not interfere).
I agree with you that the problem is related to the stm32 being a 32bits while my pc is 64.
My guess is that clang-tidy interpret the flag "-mcpu=cortex-m4".

If the extract is not ok for you, I may start over a new project that I could share.

Thank you

from clang-uml.

bkryza avatar bkryza commented on June 1, 2024

@bilboquet I've managed to reproduce the error with the following steps:

python3 -m pip install mbed-tools
mbed-tools import mbed-os-example-blinky mbed-os-example-blinky
mbed-tools configure -m NUCLEO_F411RE -t GCC_ARM
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -S . -B cmake_build/NUCLEO_F411RE/develop/GCC_ARM  -GNinja
find . -name compile_commands.json

and the following .clang-uml config:

compilation_database_dir: cmake_build/NUCLEO_F411RE/develop/GCC_ARM/
output_directory: puml
diagrams:
  test:
    type: class
    glob:
      - main.cpp
    include:
      namespaces:
        - test
    using_namespace:
      - test

I'll investigate if it's possible to resolve this issue...

from clang-uml.

bkryza avatar bkryza commented on June 1, 2024

@bilboquet I've managed to generate a diagram from this code by adding a -fms-extesions compilation flag like this:

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_FLAGS="-fms-extensions" -S . -B cmake_build/NUCLEO_F411RE/develop/GCC_ARM  -GNinja

and commenting out these 2 lines in mbed-os/platform/include/platform/mbed_retarget.h:

//typedef signed   int  ssize_t;  ///< Signed size type, usually encodes negative errors
typedef signed   long off_t;    ///< Offset in a data stream
typedef unsigned int  nfds_t;   ///< Number of file descriptors
//typedef unsigned long long fsblkcnt_t;  ///< Count of file system blocks

After that the diagram gets generated, although you still get a lot of warnings from Clang:

$ clang-uml
...
136 warnings generated.
[info] [tid 2839919] [main.cc:278] Written test diagram to puml/test.puml
$ cat puml/test.puml
@startuml
class "A" as C_0001009537205076478716
class C_0001009537205076478716 {
}
@enduml

I know it's not ideal, but for now I don't have a better solution...

from clang-uml.

bilboquet avatar bilboquet commented on June 1, 2024

Thanks a lot, not ideal but promising :)
I'll test this tomorrow and tell you what happens on my side

from clang-uml.

bilboquet avatar bilboquet commented on June 1, 2024

@bkryza
Hello
I tested your suggestions and its quite better :)
Not perfect for sure but it gives some results.

What I did

  • commented the suggested typedefs in mbed_retarget.h
  • as we are using the old mbed build tools (we are not using cmake) so I added "-fms-extensions" for every entry in the compile_commands.json
  • fixed few warnings (that obviously must be fixed in our code)

adapt my .clang-uml file according to this:

compilation_database_dir: .
output_directory: puml
diagrams:
  myproject_class:
    type: class
    glob:
      - main.cpp
    using_namespace:
      - traxens
    include:
      namespaces:
        - traxens
    exclude:
      namespaces:
        - mbed
        - std
    plantuml:
      after:
        - 'note left of {{ alias("MyProjectMain") }}: Main class of myproject library.'
  • ran clang-uml -v

The results

I ended up with this:

[debug] [tid 647827] [class_diagram_generator.cc:269] == Processing relationship --+
[debug] [tid 647827] [diagram.cc:258] Looking for alias for 967470598388489187
[debug] [tid 647827] [class_diagram_generator.cc:312] === Adding relation C_0000399580321923892100 --+ C_0000967470598388489187

clang-uml: /home/user/workspace/clang-uml/src/common/types.h:102: T& clanguml::common::optional_ref<T>::value() [with T = clanguml::common::model::diagram_element]: Assertion `value_ != nullptr' failed.
Abandon (core dumped)

Not ideal, but I have a 246kB puml/myproject_class.puml file that I can open with plantuml. As it's huge, for the moment I'm unable to tell if it's missing something in.

Questions

  • If you're interested in investigating this crash I'll be glad to help. Please just let me know.
  • Is there any way to restrict the size of the generated model? As an example for a class diagram, limit it X levels of dependencies. (It could improve readability and maybe help to find the crash).

Once again, many thanks

from clang-uml.

bkryza avatar bkryza commented on June 1, 2024

@bilboquet
First of all, which version of clang-uml are you using? If you're building the latest master, can you please build it in debug mode:

make debug

and then run clang-uml in gdb:

gdb --args /path/to/clang-uml
(gdb) run
# Wait till it crashes
(gdb) bt full

and please paste the output (at least first 10 frames)

As to the size of the generated PlantUML file, the key idea behind clang-uml is to enable fine-grained generation of diagrams by specifying custom inclusion and exclusion directives, for instance if you're interested in direct neighborhood of a specific class just create a diagram like this:

    include:
      namespaces:
        - traxens
      context:
        - traxens::MyClassA

Also you can try to remove dependency relationships which can clutter diagrams by adding exclude filter:

    exclude:
      relationships:
        - dependency

More examples are in test cases t00039 - t00042...

from clang-uml.

bilboquet avatar bilboquet commented on June 1, 2024

@bkryza
Latest master built in debug is the version I'm using :)

$ ./debug/clang-uml -V
clang-uml 0.2.2-2-g9280155
Copyright (C) 2021-2022 Bartek Kryza <[email protected]>
Built with LLVM version: 12.0.0
Using LLVM version: Ubuntu clang version 12.0.0-3ubuntu1~20.04.5

my config file to have a small diagram is (fine-grained is what I need, I'm exploring for the moment)

compilation_database_dir: .
output_directory: puml
diagrams:
  myproject_class:
    type: class #sequence include package
    generate_packages: false
    glob:
      - main.cpp
    using_namespace:
      - traxens
      - mbed
      - std
    include:
      subclasses:
        - traxens::IService
      relationships:
        - inheritance
    exclude:
      namespaces:
        - std
      access:
        - private
        - protected
        - public
    plantuml:
      after:
        - 'note left of {{ alias("MyProjectMain") }}: Main class of myproject library.'

please note that in this case the crash happens before any diagram is generated. If I comment those two lines

      subclasses:
        - traxens::IService

I get a pretty huge one. (there is still a crash and some classes are missing).

Here is the gdb bt

#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
        set = {__val = {0, 140737210005200, 140737415839744, 140736872729664, 140736872729765, 140736872729664, 140736872729664, 140736872729873, 140736872729964, 140736872729664, 140736872729964, 0, 0, 0, 0, 0}}
        pid = <optimized out>
        tid = <optimized out>
        ret = <optimized out>
#1  0x00007fffef613859 in __GI_abort () at abort.c:79
        save_stage = 1
        act = {__sigaction_handler = {sa_handler = 0x7fffdb4e4c40, sa_sigaction = 0x7fffdb4e4c40}, sa_mask = {__val = {209, 4, 4015182816, 0, 0, 140737211159576, 0, 21474836480, 4015182544, 140736951870656, 140737211191312, 0, 17861767459357248768, 140737211159576, 140737354117120, 
              140737211176328}}, sa_flags = 1436796120, sa_restorer = 0x66}
        sigs = {__val = {32, 0 <repeats 15 times>}}
#2  0x00007fffef613729 in __assert_fail_base (fmt=0x7fffef7a9588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x555555a3c510 "value_ != nullptr", file=0x555555a3c4d8 "/home/user/workspace/clang-uml/src/common/types.h", line=102, function=<optimized out>) at assert.c:92
        str = 0x7fffdb4e4c40 "@\216\310\332\377\177"
        total = 4096
#3  0x00007fffef624fd6 in __GI___assert_fail (assertion=0x555555a3c510 "value_ != nullptr", file=0x555555a3c4d8 "/home/user/workspace/clang-uml/src/common/types.h", line=102, 
    function=0x555555a3c470 "T& clanguml::common::optional_ref<T>::value() [with T = clanguml::common::model::diagram_element]") at assert.c:101
No locals.
#4  0x000055555588d737 in clanguml::common::optional_ref<clanguml::common::model::diagram_element>::value (this=0x7fffef52d478) at /home/user/workspace/clang-uml/src/common/types.h:102
        __PRETTY_FUNCTION__ = "T& clanguml::common::optional_ref<T>::value() [with T = clanguml::common::model::diagram_element]"
#5  0x000055555588ad3f in clanguml::common::generators::plantuml::generator<clanguml::config::class_diagram, clanguml::class_diagram::model::diagram>::init_env()::{lambda(std::vector<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const*, std::allocator<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const*> >&)#9}::operator()(std::vector<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const*, std::allocator<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const*> >&) const (this=0x7fffef52e470, args=std::vector of length 1, capacity 1 = {...})
    at /home/user/workspace/clang-uml/src/common/generators/plantuml/generator.h:485
        element_opt = {value_ = 0x0}
        this = 0x7fffef52e470
#6  0x00005555558aa3c0 in std::_Function_handler<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > (std::vector<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const*, std::allocator<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const*> >&), clanguml::common::generators::plantuml::generator<clanguml::config::class_diagram, clanguml::class_diagram::model::diagram>::init_env()::{lambda(std::vector<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const*, std::allocator<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const*> >&)#9}>::_M_invoke(std::_Any_data const&, std::vector<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const*, std::allocator<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const*> >&) (__functor=..., __args#0=std::vector of length 1, capacity 1 = {...})
    at /usr/include/c++/9/bits/std_function.h:286
No locals.
#7  0x00005555558736ce in std::function<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > (std::vector<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const*, std::allocator<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const*> >&)>::operator()(std::vector<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const*, std::allocator<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const*> >&) const (this=0x7fffdb66d290, __args#0=std::vector of length 1, capacity 1 = {...}) at /usr/include/c++/9/bits/std_function.h:688
No locals.
#8  0x0000555555868eff in inja::Renderer::visit (this=0x7fffef52db20, node=...) at /home/user/workspace/clang-uml/thirdparty/inja/inja.hpp:2503
        args = std::vector of length 1, capacity 1 = {0x7fffdb247a10}
#9  0x000055555585d806 in inja::FunctionNode::accept (this=0x7fffdb66d230, v=...) at /home/user/workspace/clang-uml/thirdparty/inja/inja.hpp:587
No locals.
#10 0x0000555555865a0c in inja::Renderer::eval_expression_list[abi:cxx11](inja::ExpressionListNode const&) (this=0x7fffef52db20, expression_list=...) at /home/user/workspace/clang-uml/thirdparty/inja/inja.hpp:2152
        result = 0x7fffef52d960
#11 0x0000555555869f21 in inja::Renderer::visit (this=0x7fffef52db20, node=...) at /home/user/workspace/clang-uml/thirdparty/inja/inja.hpp:2558
No locals.
#12 0x000055555585d90a in inja::ExpressionListNode::accept (this=0x7fffdb138660, v=...) at /home/user/workspace/clang-uml/thirdparty/inja/inja.hpp:599
No locals.
#13 0x0000555555866014 in inja::Renderer::visit (this=0x7fffef52db20, node=...) at /home/user/workspace/clang-uml/thirdparty/inja/inja.hpp:2246
        n = std::shared_ptr<inja::AstNode> (use count 1, weak count 0) = {get() = 0x7fffdb138660}
        __for_range = std::vector of length 3, capacity 4 = {std::shared_ptr<inja::AstNode> (use count 1, weak count 0) = {get() = 0x7fffdb2f1fc0}, std::shared_ptr<inja::AstNode> (use count 1, weak count 0) = {get() = 0x7fffdb138660}, 
          std::shared_ptr<inja::AstNode> (use count 1, weak count 0) = {get() = 0x7fffe0003e50}}
        __for_begin = std::shared_ptr<inja::AstNode> (use count 1, weak count 0) = {get() = 0x7fffdb138660}
        __for_end = <error reading variable: Cannot access memory at address 0x736d617261506b6b>
#14 0x000055555558dd0e in inja::BlockNode::accept (this=0x7fffef52de90, v=...) at /home/user/workspace/clang-uml/thirdparty/inja/inja.hpp:413
No locals.
#15 0x000055555586bbef in inja::Renderer::render_to (this=0x7fffef52db20, os=..., tmpl=..., data=..., loop_data=0x0) at /home/user/workspace/clang-uml/thirdparty/inja/inja.hpp:2708
No locals.
#16 0x000055555586e22c in inja::Environment::render_to (this=0x7fffef52e4c8, os=..., tmpl=..., data=...) at /home/user/workspace/clang-uml/thirdparty/inja/inja.hpp:2858
No locals.
#17 0x000055555586e11c in inja::Environment::render (this=0x7fffef52e4c8, tmpl=..., data=...) at /home/user/workspace/clang-uml/thirdparty/inja/inja.hpp:2822
        os = <incomplete type>
#18 0x000055555586e051 in inja::Environment::render (this=0x7fffef52e4c8, input="note left of {{ alias(\"MyProjectMain\") }}: Main class of myproject library.", data=...) at /home/user/workspace/clang-uml/thirdparty/inja/inja.hpp:2817
No locals.
#19 0x000055555587c4cc in clanguml::common::generators::plantuml::generator<clanguml::config::class_diagram, clanguml::class_diagram::model::diagram>::generate_plantuml_directives (this=0x7fffef52e470, ostr=..., directives=std::vector of length 1, capacity 1 = {...})
    at /home/user/workspace/clang-uml/src/common/generators/plantuml/generator.h:188
        directive = ""
        alias_match = std::tuple containing = {[1] = <error reading variable: Cannot create a lazy string with address 0x0, and a non-zero length.>, [2] = 140736951496288, [3] = 140736866497216}
        d = "note left of {{ alias(\"MyProjectMain\") }}: Main class of myproject library."
        __for_range = std::vector of length 1, capacity 1 = {"note left of {{ alias(\"MyProjectMain\") }}: Main class of myproject library."}
        __for_begin = "note left of {{ alias(\"MyProjectMain\") }}: Main class of myproject library."
        __for_end = <error reading variable: Cannot create a lazy string with address 0x0, and a non-zero length.>
#20 0x0000555555858bc5 in clanguml::class_diagram::generators::plantuml::generator::generate (this=0x7fffef52e470, ostr=...) at /home/user/workspace/clang-uml/src/class_diagram/generators/plantuml/class_diagram_generator.cc:536
No locals.
#21 0x00005555555e0412 in clanguml::common::generators::plantuml::operator<< <clanguml::config::class_diagram, clanguml::class_diagram::model::diagram> (os=..., g=...) at /home/user/workspace/clang-uml/src/common/generators/plantuml/generator.h:97

from clang-uml.

bkryza avatar bkryza commented on June 1, 2024

@bilboquet Do you have in your code MyProjectMain ?

If not please remove the:

    plantuml:
      after:
        - 'note left of {{ alias("MyProjectMain") }}: Main class of myproject library.'

It cannot find the PlantUML alias of a class MyProjectMain which doesn't seem to exist and thus crashes on template renderer (of course it should report a more useful error message than segfault;-) )

from clang-uml.

bilboquet avatar bilboquet commented on June 1, 2024

@bkryza
You got it!!!
I misunderstood the documentation, sorry.
I still have a lot of warning but no crash anymore, that's great!
And I have a very nice inheritance diagram for the class I choose.

Many thanks to you.
(should I close the issue?)

from clang-uml.

bkryza avatar bkryza commented on June 1, 2024

@bilboquet Glad it helped :-)

from clang-uml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.