Menu

dump files

2017-11-02
2017-11-17
  • David Brady

    David Brady - 2017-11-02

    I would like the ability to specify dump file locations from the command line. I've just started using that feature at work, and it's very inconvenient having the dump files written to the source directory. I have patches that I am more than happy to share, but the bug tracker is private, and there's nobody in chat.

    From 4f9bb0731892ee258794adf1fe32774f1ca68f7e Mon Sep 17 00:00:00 2001
    From: David Brady <classic.grey@gmail.com>
    Date: Thu, 2 Nov 2017 19:00:34 -0400
    Subject: [PATCH] Add ability to specify dump file from the command line
    
    ---
     cli/cmdlineparser.cpp | 4 ++++
     1 file changed, 4 insertions(+)
    
    diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp
    index b3b514a..64fb865 100644
    --- a/cli/cmdlineparser.cpp
    +++ b/cli/cmdlineparser.cpp
    @@ -146,6 +146,10 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
                 // dump cppcheck data
                 else if (std::strcmp(argv[i], "--dump") == 0)
                     _settings->dump = true;
    +            else if (std::strncmp(argv[i], "--dump=", 7) == 0) {
    +                _settings->dump = true;
    +                _settings->dumpFile = Path::fromNativeSeparators(argv[i] + 7);
    +            }
    
                 // (Experimental) exception handling inside cppcheck client
                 else if (std::strcmp(argv[i], "--exception-handling") == 0)
    -- 
    2.7.4
    
    From 800b63ccc64739ef5d76f6f2597be735712dad42 Mon Sep 17 00:00:00 2001
    From: David Brady <classic.grey@gmail.com>
    Date: Thu, 2 Nov 2017 18:43:36 -0400
    Subject: [PATCH] Write dump files to current directory by default
    
    ---
     lib/cppcheck.cpp | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp
    index 8db5536..a44fb6c 100644
    --- a/lib/cppcheck.cpp
    +++ b/lib/cppcheck.cpp
    @@ -194,7 +194,7 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin
             // write dump file xml prolog
             std::ofstream fdump;
             if (_settings.dump) {
    -            const std::string dumpfile(_settings.dumpFile.empty() ? (filename + ".dump") : _settings.dumpFile);
    +            const std::string dumpfile(_settings.dumpFile.empty() ? (Path::stripDirectoryPart(filename) + ".dump") : _settings.dumpFile);
                 fdump.open(dumpfile.c_str());
                 if (fdump.is_open()) {
                     fdump << "<?xml version=\"1.0\"?>" << std::endl;
    -- 
    2.7.4
    
     

    Last edit: David Brady 2017-11-02
  • Daniel Marjamäki

    I agree.

    the GUI writes the dump files in a custom location (in the cppcheck-build-dir).. but there is no way to access that feature from command line. Maybe your --dump= command is ok but as far as I see you then need to invoke cppcheck separately on each source file.

    Can you please open a Pull Request in github?

     
  • Daniel Marjamäki

    Would it suit your needs if you can specify a folder where all the dump files will be saved?

    your default option to put the dump files in current directory makes sense. however it must be handled when different files have the same filename "subfolder1/file.c" and "subfolder2/file.c".

     
  • David Brady

    David Brady - 2017-11-05

    I'll see about setting up a github account.

    And yeah, I forgot that cppcheck allows you to check multiple files at once (I'm just using it like a compilert). Maybe if we were to mirror the relative directory location from the current working directory (or --dump-dir?), if checking a directory?

     
  • David Brady

    David Brady - 2017-11-12

    I had a closer look at this today. My original proposal doesn't appear to work, as cppcheck also allows multiple file or directory arguments. So how about maybe just appending a (2) after the name if a dump file exists?

     
  • David Brady

    David Brady - 2017-11-12

    Actually no, that would make it so that I would never quite be sure if the file I was looking at was actually for my current run or some previous run if I failed to clean my output. I definitely wouldn't want that

    How about prepending a numbered directory name in front of a relative directory name in the dump file output directory (in the case of a recursive directory argument)? That would require some rather extensive changes to the code though, as the files map would likely have to change from a size_t to a struct value for size, arg number, and basename. Then pass in the desired dump name into the check function?

    Does that sound reasonable?

     
  • Daniel Marjamäki

    I would recommend that "Cppcheck build dir" is used overall... so if that is specified then how about writing the dump files there in the CLI also to start with? Then the GUI and CLI works the same.

    In the "Cppcheck build dir", a files.txt is generated the contains a mapping for source files and files in the Cppcheck build dir. Here is an example files.txt I got when analysing Cppcheck lib..

    analyzerinfo.a1::lib/analyzerinfo.cpp
    astutils.a1::lib/astutils.cpp
    check.a1::lib/check.cpp
    check64bit.a1::lib/check64bit.cpp
    checkassert.a1::lib/checkassert.cpp
    checkautovariables.a1::lib/checkautovariables.cpp
    checkbool.a1::lib/checkbool.cpp
    

    In the GUI, the dump file for lib/analyzerinfo.cpp will get the name analyzerinfo.a1.dump. That name is guaranteed to be unique even if there are many files with the name "analyzerinfo.cpp" in different folders. The extensions will be "a1", "a2", "a3", ...

    Would this be a good solution for you?

     

    Last edit: Daniel Marjamäki 2017-11-16
  • Daniel Marjamäki

    By the way.. it is not important what the filenames of the dumpfiles are. They can be "1.dump", "2.dump", "3.dump", ....

    All information the addons need are in the dumpfile.

    In the long run I think it would be nice with a builtin functionality in Cppcheck that would execute the addons. Like:

    ./cppcheck --addon=misra.py myfolder 2> misra-warnings.txt
    

    And ideally the user does not need to worry about the dumpfiles at all.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.