aboutsummaryrefslogtreecommitdiff
path: root/srcpos.c
AgeCommit message (Collapse)AuthorFilesLines
2023-03-01srcpos.c: fix -Wwrite-stringsMarc-André Lureau1-6/+6
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-02-27Do not redefine _GNU_SOURCE if already setMarc-André Lureau1-0/+2
Or else, compilation will fail. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-01-13srcpos: increase MAX_SRCFILE_DEPTHIgnacy Kuchciński1-1/+1
Some kernels require the MAX_SRCFILE_DEPTH to be bigger than 100, and since it's just a sanity check to detect infinite recursion it shouldn't hurt increasing it to 200. Signed-off-by: Ignacy Kuchciński <ignacykuchcinski@gmail.com> Message-Id: <CAJq_QG0BHBQYT4RnVi0QSxM_vFK2K-5k1eTpJnwZQtWbKnCBJA@mail.gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-06-21dtc: Replace GPLv2 boilerplate/reference with SPDX tagsRob Herring1-15/+1
Replace instances of GPLv2 or later boilerplate with SPDX tags. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20190620211944.9378-2-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-19annotations: add the annotation functionalityJulia Lawall1-3/+116
Provide the new command-line option: --annotate (abbreviated -T) --annotate provides one or more filenames and line numbers indicating the origin of a given line. The filename is expressed relative the the filename provided on the command line. Nothing is printed for overlays, etc. -T can be repeated giving more verbose annotations. These consist of one or more tuples of: filename, starting line, starting column, ending line ending column. The full path is given for the file name. Overlays, etc are annotated with <no-file>:<no-line>. The verbose annotations may be too verbose for normal use. There are numerous changes in srcpos.c to provide the relative filenames (variables initial_path, initial_pathlen and initial_cpp, new functions set_initial_path and shorten_to_initial_path, and changes in srcfile_push and srcpos_set_line). The change in srcpos_set_line takes care of the case where cpp is used as a preprocessor. In that case the initial file name is not the one provided on the command line but the one found at the beginnning of the cpp output. shorten_to_initial_path only returns a string if it has some shortening to do. Otherwise it returns NULL and relies on the caller to use the initial string. This simplifies memory management, by making clear to the caller whether a new string is allocated. The new functions srcpos_string_comment, srcpos_string_first, and srcpos_string_last print the annotations. srcpos_string_comment is recursive to print a list of source file positions. Various changes are sprinkled throughout treesource.c to print the annotations. Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-19annotations: add positionsJulia Lawall1-0/+22
Extend the parser to record positions, in build_node, build_node_delete, and build_property. srcpos structures are added to the property and node types, and to the parameter lists of the above functions that construct these types. Nodes and properties that are created by the compiler rather than from parsing source code have NULL as the srcpos value. merge_nodes, defined in livetree.c, uses srcpos_extend to combine multiple positions, resulting in a list of positions. srcpos_extend is defined in srcpos.c. New elements are added at the end. This requires the srcpos type, define in srcpos.h, to be a list structure with a next field. This next field is initialized to NULL in srcpos.h, in the macro YYLLOC_DEFAULT invoked implicitly by the generated parser code. Another change to srcpos.c is to make srcpos_copy always do a full copy, including a copy of the file substructure. This is required because when dtc is used on the output of cpp, the successive detected file names overwrite the file name in the file structure. The next field does not need to be deep copied, because it is always NULL when srcpos_copy is called; an assert checks for this. File names are only updated in uncopied position structures. Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-14srcpos: Remove srcpos_emptyDavid Gibson1-12/+0
Nothing was actually using it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-14Revert "annotations: add positions"David Gibson1-22/+0
This reverts commit baa1d2cf7894a32bf2f640ef40ebce561b2df565. Turns out this introduced memory badness. valgrind picks it up on x86, but it straight out SEGVs on x86. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-13annotations: add positionsJulia Lawall1-0/+22
Extend the parser to record positions, in build_node, build_node_delete, and build_property. srcpos structures are added to the property and node types, and to the parameter lists of the above functions that construct these types. Nodes and properties that are created by the compiler rather than from parsing source code have NULL as the srcpos value. merge_nodes, defined in livetree.c, uses srcpos_extend to combine multiple positions, resulting in a list of positions. srcpos_extend is defined in srcpos.c. New elements are added at the end. The srcpos type, define in srcpos.h, is now a list structure with a next field. Another change to srcpos.c is to make srcpos_copy always do a full copy, including a copy of the file substructure. This is required because when dtc is used on the output of cpp, the successive detected file names overwrite the file name in the file structure. The next field does not need to be deep copied, because it is only updated in newly copied positions and the positions to which it points have also been copied. File names are only updated in uncopied position structures. Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-01-23srcpos: drop special handling of tabJulia Lawall1-5/+0
Align column number with those reported by gcc. Thus, do not make a tab count as 8 spaces. Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-02-08dtc: pos parameter to srcpos_string() can't be NULLDavid Gibson1-1/+1
None of the callers ever pass a NULL to srcpos_string(), so the check for it is not necessary. Furthermore, checking it make Coverity complain about the raw dereferences which follow later in the function. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-07-13Remove unused srcpos_dump() functionDavid Gibson1-15/+0
srcpos_dump() has no current users, and I have no plans to use it. So remove it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-05-25Use xasprintf() in srcposDavid Gibson1-12/+8
Now that we have an xasprintf() helper function, use it to simplify the srcpos_string() implementation. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-06-19Open binary files in binary modeAndrei Errapart1-1/+1
The "b" flag to fopen() is generally a no-op on Unix-like systems, but may be important on other systems, including Windows. Signed-off-by: Andrei Errapart <andrei@errapartengineering.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-01-25dtc: avoid shadowing dirname()Florian Fainelli1-2/+2
dirname() is declared as a function, and later on try_open() another variable dirname is used, which shadows the dirname() function declaration and will produce the following warnings/errors with -Wshadow turned on: srcpos.c: In function 'try_open': srcpos.c:71:35: error: declaration of 'dirname' shadows a global declaration [-Werror=shadow] srcpos.c:37:14: error: shadowed declaration is here [-Werror=shadow] srcpos.c: In function 'srcfile_add_search_path': srcpos.c:183:42: error: declaration of 'dirname' shadows a global declaration [-Werror=shadow] srcpos.c:37:14: error: shadowed declaration is here [-Werror=shadow] cc1: all warnings being treated as errors Fix this by renaming the function dirname() to get_dirname(). Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
2014-01-01Make srcpos_{v,}error() more widely usefulDavid Gibson1-6/+6
Allow them to take a prefix argument giving the general type of error, which will be useful in future. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-01-01Fix memory leak in srcpos_verror()David Gibson1-1/+3
Since dtc runs are short, we don't care that much about memory leaks. Still, leaking the source position string every time we print an error messages is pretty nasty. Fix it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-01-01Fix indentation of srcpos_verror()David Gibson1-5/+5
Somehow this function ended up with a 7 space indent, instead of the usual 8 space (1 tab) indent. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-01-01Fix typo in type of srcpos_verror() et al.David Gibson1-2/+2
The srcpos_verror() and srcpos_error() functions declare the format string as 'char const *' instead of 'const char *'. Fix it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-01-01Remove unused srcpos_warn() functionDavid Gibson1-17/+0
This function has no users, and we can replace it more generally later. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-10-28Use stdbool more widelyDavid Gibson1-2/+2
We already use the C99 bool type from stdbool.h in a few places. However there are many other places we represent boolean values as plain ints. This patch changes that. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-10-16dtc: srcpos_verror() should print to stderrMichael Ellerman1-3/+3
Errors should go to stderr. Signed-off-by: Michael Ellerman <michael@ellerman.id.au> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-09-28dtc: cpp co-existence: add support for #line directivesStephen Warren1-0/+6
Line control directives of the following formats are supported: #line LINE "FILE" # LINE "FILE" [FLAGS] This allows dtc to consume the output of pre-processors, and to provide error messages that refer to the original filename, including taking into account any #include directives that the pre-processor may have performed. Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-03-18dtc: Add -i option to support search pathsSimon Glass1-7/+85
It is often inconvenient to place device tree files in the same directory as their includes, or to specify the full path to include files. An example of this is in U-Boot where we have a .dtsi file for each SOC type, and this is included by the board .dts file. We need to either use a mechanism like: /include/ ARCH_CPU_DTS with sed or cpp to perform the replacement with the correct path, or we must specify the full path in the file: /include/ "../../arch/arm/dts/tegra20.dtsi" The first option is not desirable since it requires anyone compiling the file to first pre-process it. The second is not desirable since it introduces a path which is project-specific into a file which is supposed to be a hardware description. For example Linux and U-Boot are unlikely to put these include files in the same place. It is much more convenient to specify the search patch on the command line as is done with C pre-processors, for example. Introduce a -i option to add to the list of search paths used to find source and include files. We cannot use -I as it is already in use. Other suggestions welcome. Signed-off-by: Simon Glass <sjg@chromium.org>
2012-01-13dtc: Implement -d option to write out a dependency fileStephen Warren1-0/+4
This will allow callers to rebuild .dtb files when any of the /include/d .dtsi files are modified, not just the top-level .dts file. Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2010-10-20Create new and use new print_error that uses printf style formatting.John Bonesio1-8/+13
yyerror is meant to be called by the parser internal code, and it's interface is limited. Instead create and call a new error message routine that allows formatted strings to be used. yyerror uses the new routine so error formatting remains consistent. Signed-of-by: John Bonesio <bones@secretlab.ca> Acked-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
2010-01-14dtc: Cleanup YYLTYPE and YYLLOC_DEFAULT declarationsDavid Gibson1-11/+11
This patch makes some small cleanups to the declaration of YYLTYPE, YYLLOC_DEFAULT and related things. - We used to use undocumented magic #defines for bison, YYLTYPE_IS_DECLARED and YYLTYPE_IS_TRIVIAL. This may not be portable across bison versions. Instead define YYLTYPE as a macro in terms of struct srcpos, as the info pages suggest. - Our kernel-derived coding style discourages typedefed structures. So use 'struct srcpos' instead of 'srcpos' throughout'. - Indent the YYLLOC_DEFAULT macro according to our coding style (it was in GNU indent style, since it was taken from the example in the bison info). Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-01-14dtc: Cleanup srcpos_string()David Gibson1-29/+16
There are several small problems with the current srcpos_string(). - The code unnecessarily uses a temp buffer and two rounds of *printf(); a single asprintf() will suffice. - With previous changes, pos->file->name can never be NULL, and the name field for a srcfile bound to stdin is already set to something sensible. - On allocation failure in asprintf() it returns a bogus result, instead of causing a fatal error like every other failed allocation. - The format for representing file/line/column is gratuitously different from the file/line format we used to use, and the format used by gcc and bison. This patch addresses all of these. There remains the problem that asprintf() is not portable, but that can wait until another patch. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-01-14dtc: Cleanup line number tracking, add column number trackingDavid Gibson1-1/+32
Our YYLTYPE current carries around first and last line and first and last column information. However, of these, on the first line information is actually filled in properly. Furthermore, filling in the line number information from yylineno is kind of clunky: we have to copy its value to the srcfile stack and back to handle include file positioning correctly. This patch cleans this up. We turn off flex's yylineno option and instead track the line and column number ourselves from YY_USER_ACTION. The line and column number are stored directly inside the srcfile_state structure, so it's automatically a per-file quantity. We now also fill in all the yylloc from YY_USER_ACTION. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-01-14dtc: Simpler interface to source file managementDavid Gibson1-83/+68
This patch cleans up our handling of input files, particularly dts source files, but also (to an extent) other input files such as those used by /incbin/ and those used in -I dtb and -I fs modes. We eliminate the current clunky mechanism which combines search paths (which we don't actually use at present) with the open relative to current source file behaviour, which we do. Instead there's a single srcfile_relative_open() entry point for callers which opens a new input file relative to the current source file (which the srcpos code tracks internally). It doesn't currently do search paths, but we can add that later without messing with the callers, by drawing the search path from a global (which makes sense anyway, rather than shuffling it around the rest of the processing code). That suffices for non-dts input files. For the actual dts files, srcfile_push() and srcfile_pop() wrappers open the file while also keeping track of it as the current source file for future opens. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-10-03Enhance source position implementation.Jon Loeliger1-9/+133
Implemented some print and copy routines. Made empty srcpos objects that will be used later. Protected .h file from multiple #include's. Added srcpos_error() and srcpos_warn(). Signed-off-by: Jon Loeliger <jdl@freescale.com>
2008-10-03Implement and use an xstrdup() functionJon Loeliger1-2/+2
Many places in dtc use strdup(), but none of them actually check the return value to see if the implied allocation succeeded. This is a potential bug, which we fix in the patch below by replacing strdup() with an xstrdup() which in analogy to xmalloc() will quit with a fatal error if the allocation fails. I felt the introduciton of util.[ch] was a better choice for utility oriented code than directly using srcpos.c for the new string function. This patch is a re-factoring of Dave Gibson's similar patch. Signed-off-by: Jon Loeliger <jdl@freescale.com>
2008-03-23dtc: Make dtc_open_file() die() if unable to open requested fileDavid Gibson1-7/+4
All current callers of dtc_open_file() immediately die() if it returns an error. In a non-interative tool like dtc, it's hard to see what you could sensibly do to recover from a failure to open an input file in any case. Therefore, make dtc_open_file() itself die() if there's an error opening the requested file. This removes the need for error checking at the callsites, and ensures a consistent error message in all cases. While we're at it, change the rror message from fstree.c when we fail to open the input directory to match dtc_open_file()'s error message. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-01-11Remove const from dtc_file::dir.Scott Wood1-2/+2
Signed-off-by: Scott Wood <scottwood@freescale.com>
2008-01-07Convert malloc() uses to xmalloc().Scott Wood1-9/+3
Signed-off-by: Scott Wood <scottwood@freescale.com>
2008-01-07Handle absolute pathnames correctly in dtc_open_file.Scott Wood1-0/+12
Also, free file->dir when freeing file. Signed-off-by: Scott Wood <scottwood@freescale.com>
2008-01-04Look for include files in the directory of the including file.Scott Wood1-59/+67
Looking in the diretory dtc is invoked from is not very useful behavior. As part of the code reorganization to implement this, I removed the uniquifying of name storage -- it seemed a rather dubious optimization given likely usage, and some aspects of it would have been mildly awkward to integrate with the new code. Signed-off-by: Scott Wood <scottwood@freescale.com>
2007-03-26DTC: Add support for a C-like #include "file" mechanism.Jon Loeliger1-0/+105
Keeps track of open files in a stack, and assigns a filenum to source positions for each lexical token. Modified error reporting to show source file as well. No policy on file directory basis has been decided. Still handles stdin. Tested on all arch/powerpc/boot/dts DTS files Signed-off-by: Jon Loeliger <jdl@freescale.com>