[cfe-dev] redirect clang warning/error ouput

mats petersson via cfe-dev cfe-dev at lists.llvm.org
Thu Aug 17 10:55:07 PDT 2017


Hi Ogzu,

It is customary, when replying to a mailing list reply, to "reply all" (or
at the very least include the mailing list as well as the person that
replied to you), so that other people a) can see any further discussion (it
helps others) and b) perhaps reply if they feel like (either to help out or
to correct something that went wrong).

Basically you need to use the clang::Diagnostic and related functionality.
Depending on what you actually want to have your string output do, you may
want to derive a class from clang::DiagnosticConsumer, and implement (at
least) the HandleDiagnostic function in that derived class - there are some
"already prepared" classes, such as TextDiagnosticBuffer that may well do
what you want (I haven't looked closely into how this works).

There's a bit of discussion on "diagnostics" here:
http://www.goldsborough.me/c++/clang/llvm/tools/2017/02/24/00-00-06-emitting_diagnostics_and_fixithints_in_clang_tools/

You probably want to read up about raw_ostream and raw_string_ostream too -
as they are useful tools for capturing output from clang, and I'm sure I've
seem such things in previous posts, but my search for that isn't going well.

--
Mats

On 17 August 2017 at 12:15, ogzu rasa <karpalo1987 at gmail.com> wrote:

> Hello,
> Thanks for response.
> Sorry I didn't precise that i dev a tool with clang lib tooling and I want
> to redirect the clang message to bufffer (std::stringstream).
> Is there any example/tutorial for write a driver for the compiler ?
>
> thanks
>
> 2017-08-17 11:14 GMT+02:00 mats petersson <mats at planetcatfish.com>:
>
>> To a "buffer" (along the lines of `std::stringstream`) is also possible
>> if you write your own "driver" for the compiler, but clang as an exectuable
>> file has no concept of "buffer" as output destination.
>>
>> I'm not going to look up exactly how to do write the necessary code to
>> capture the output from the compiler components, but I know it's possible,
>> and there have been posts about it in the past.
>>
>> --
>> Mats
>>
>> On 17 August 2017 at 02:46, Jonas Devlieghere via cfe-dev <
>> cfe-dev at lists.llvm.org> wrote:
>>
>>> Hi Ogzu,
>>>
>>> Clang prints both errors and warnings to stderr. You could redirect
>>> stdout to a file and redirect stderr to stdout: clang foo.c > file 2>&1
>>>
>>> Cheers,
>>> Jonas
>>>
>>> On Wed, Aug 16, 2017 at 4:39 PM, ogzu rasa via cfe-dev <
>>> cfe-dev at lists.llvm.org> wrote:
>>>
>>>> Hello,
>>>> How can I redirect clang (version 3.8.1) warning/error message to a
>>>> buffer ?
>>>>
>>>> Thanks in advance for helps,
>>>> ogzu
>>>>
>>>>
>>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> Garanti
>>>> sans virus. www.avast.com
>>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
>>>> <#m_3763838836873779072_m_9069389996354039115_m_6012979265466226631_m_7454206286853231618_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>>>
>>>> _______________________________________________
>>>> cfe-dev mailing list
>>>> cfe-dev at lists.llvm.org
>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>>>
>>>>
>>>
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170817/a77024d0/attachment.html>


More information about the cfe-dev mailing list