Changeset 1703041 in rtems-tools


Ignore:
Timestamp:
Mar 24, 2015, 3:37:35 AM (4 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.10, 4.11, master
Children:
b988768
Parents:
29ad92c
Message:

rtems-tld: Add lock and buffer allocator support to generators.

Generators can control a lock and buffer allocation so a single
alloc can happen and a lock released.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • linkers/rtems-tld.cpp

    r29ad92c r1703041  
    172172    {
    173173      std::string  name;            /**< The name of this wrapper. */
     174      std::string  lock_local;      /**< Code template to declare a local lock variable. */
     175      std::string  lock_acquire;    /**< The lock acquire if provided. */
     176      std::string  lock_release;    /**< The lock release if provided. */
     177      std::string  buffer_local;    /**< Code template to declare a local buffer variable. */
     178      std::string  buffer_alloc;    /**< Code template to perform a buffer allocation. */
    174179      rld::strings headers;         /**< Include statements. */
    175180      rld::strings defines;         /**< Define statements. */
     
    552557       * A generator section optionally contain one or more records of:
    553558       *
    554        * # headers     A list of sections containing headers or header records.
    555        * # header      A list of include string that are single or double quoted.
    556        * # defines     A list of sections containing defines or define record.
    557        * # define      A list of define string that are single or double quoted.
    558        * # code-blocks A list of section names of code blocks.
    559        * # includes    A list of files to include.
     559       * # headers      A list of sections containing headers or header records.
     560       * # header       A list of include string that are single or double quoted.
     561       * # defines      A list of sections containing defines or define record.
     562       * # define       A list of define string that are single or double quoted.
     563       * # entry-trace  The wrapper call made on a function's entry.  Returns `bool
     564       *                where `true` is the function is being traced. This call is made
     565       *                without the lock being held if a lock is defined.
     566       * # arg-trace    The wrapper call made for each argment to the trace function if
     567       *                the function is being traced. This call is made without the
     568       *                lock being held if a lock is defined.
     569       * # exit-trace   The wrapper call made after a function's exit. Returns `bool
     570       *                where `true` is the function is being traced. This call is made
     571       *                without the lock being held if a lock is defined.
     572       * # ret-trace    The wrapper call made to log the return value if the funciton
     573       *                is being traced. This call is made without the lock being held
     574       *                if a lock is defined.
     575       * # lock-local   The wrapper code to declare a local lock variable.
     576       * # lock-acquire The wrapper code to acquire the lock.
     577       * # lock-release The wrapper code to release the lock.
     578       * # buffer-local The wrapper code to declare a buffer index local variable.
     579       * # buffer-alloc The wrapper call made with a lock held if defined to allocate
     580       *                buffer space to hold the trace data. A suitable 32bit buffer
     581       *                index is returned. If there is no space an invalid index is
     582       *                returned. The generator must handle any overhead space needed.
     583       *                the generator needs to make sure the space is available before
     584       *                making the alloc all.
     585       * # code-blocks  A list of code blcok section names.
     586       * # code         A code block in `<<CODE ... CODE` (without the single quote).
     587       * # includes     A list of files to include.
     588       *
     589       * The following macros can be used in specific wrapper calls. The lists of
     590       * where you can use them is listed before. The macros are:
     591       *
     592       * # @FUNC_NAME@      The trace function name as a quote C string.
     593       * # @FUNC_INDEX@     The trace function index as a held in the sorted list
     594       *                    of trace functions by teh trace linker. It can be
     595       *                    used to index the `names`, `enables` and `triggers`
     596       *                    data.
     597       * # @FUNC_LABEL@     The trace function name as a C label that can be
     598       *                     referenced. You can take the address of the label.
     599       * # @FUNC_DATA_SIZE@ The size of the daya in bytes.
     600       * # @ARG_NUM@        The argument number to the trace function.
     601       * # @ARG_TYPE@       The type of the argument as a C string.
     602       * # @ARG_SIZE@       The size of the type of the argument in bytes.
     603       * # @ARG_LABEL@      The argument as a C label that can be referenced.
     604       * # @RET_TYPE@       The type of the return value as a C string.
     605       * # @RET_SIZE@       The size of the type of the return value in bytes.
     606       * # @RET_LABEL@      The retrun value as a C label that can be referenced.
     607       *
     608       * The `buffer-alloc`, `entry-trace` and `exit-trace` can be transformed using
     609       *  the following  macros:
     610       *
     611       * # @FUNC_NAME@
     612       * # @FUNC_INDEX@
     613       * # @FUNC_LABEL@
     614       * # @FUNC_DATA_SZIE@
     615       *
     616       * The `arg-trace` can be transformed using the following macros:
     617       *
     618       * # @ARG_NUM@
     619       * # @ARG_TYPE@
     620       * # @ARG_SIZE@
     621       * # @ARG_LABEL@
     622       *
     623       * The `ret-trace` can be transformed using the following macros:
     624       *
     625       * # @RET_TYPE@
     626       * # @RET_SIZE@
     627       * # @RET_LABEL@
    560628       *
    561629       * @note The quoting and list spliting is a little weak because a delimiter
     
    570638      parse (config, section, "code-blocks", "code",   code, false);
    571639
     640      if (section.has_record ("lock-local"))
     641        lock_local = rld::dequote (section.get_record_item ("lock-local"));
     642      if (section.has_record ("lock-acquire"))
     643        lock_acquire = rld::dequote (section.get_record_item ("lock-acquire"));
     644      if (section.has_record ("lock-release"))
     645        lock_release = rld::dequote (section.get_record_item ("lock-release"));
     646      if (section.has_record ("buffer-local"))
     647        buffer_local = rld::dequote (section.get_record_item ("buffer-local"));
     648      if (section.has_record ("buffer-local"))
     649        buffer_alloc = rld::dequote (section.get_record_item ("buffer-alloc"));
    572650      if (section.has_record ("entry-trace"))
    573651        entry_trace = rld::dequote (section.get_record_item ("entry-trace"));
     
    9951073            const signature& sig = (*si).second;
    9961074
     1075            std::stringstream lss;
     1076            lss << count;
     1077
     1078            std::string l;
     1079
    9971080            c.write_line("");
     1081
     1082            if (sig.has_args () || (sig.has_ret () && !generator_.ret_trace.empty ()))
     1083            {
     1084              bool added = false;
     1085              l = "#define FUNC_DATA_SIZE_" + sig.name + " (";
     1086              if (sig.has_args ())
     1087              {
     1088                for (size_t a = 0; a < sig.args.size (); ++a)
     1089                {
     1090                  if (added)
     1091                    l += " + ";
     1092                  else
     1093                    added = true;
     1094                  l += "sizeof(" + sig.args[a] + ')';
     1095                }
     1096              }
     1097              if (sig.has_ret () && !generator_.ret_trace.empty ())
     1098              {
     1099                if (added)
     1100                  l += " + ";
     1101                else
     1102                  added = true;
     1103                l += "sizeof(" + sig.ret + ')';
     1104              }
     1105              if (!added)
     1106                l += '0';
     1107              l += ')';
     1108              c.write_line(l);
     1109            }
     1110
    9981111            c.write_line(sig.decl () + ";");
    9991112            c.write_line(sig.decl ("__real_") + ";");
     
    10011114            c.write_line("{");
    10021115
     1116            if (!generator_.lock_local.empty ())
     1117              c.write_line(generator_.lock_local);
     1118
     1119            if (!generator_.buffer_local.empty ())
     1120              c.write_line(generator_.buffer_local);
     1121
    10031122            if (sig.has_ret ())
    10041123              c.write_line(" " + sig.ret + " ret;");
    10051124
    1006             std::stringstream lss;
    1007             lss << count;
    1008 
    1009             std::string l;
    1010 
    1011             if (!generator_.entry_trace.empty ())
     1125            if (!generator_.lock_acquire.empty ())
     1126              c.write_line(generator_.lock_acquire);
     1127
     1128            if (!generator_.buffer_alloc.empty ())
    10121129            {
    1013               std::string       l = ' ' + generator_.entry_trace;
     1130              l = " " + generator_.buffer_alloc;
    10141131              l = rld::find_replace (l, "@FUNC_NAME@", '"' + sig.name + '"');
    10151132              l = rld::find_replace (l, "@FUNC_INDEX@", lss.str ());
    10161133              l = rld::find_replace (l, "@FUNC_LABEL@", sig.name);
     1134              l = rld::find_replace (l, "@FUNC_DATA_SIZE@", "FUNC_DATA_SIZE_" + sig.name);
     1135              c.write_line(l);
     1136            }
     1137
     1138            if (!generator_.lock_release.empty ())
     1139              c.write_line(generator_.lock_release);
     1140
     1141            if (!generator_.entry_trace.empty ())
     1142            {
     1143              l = " " + generator_.entry_trace;
     1144              l = rld::find_replace (l, "@FUNC_NAME@", '"' + sig.name + '"');
     1145              l = rld::find_replace (l, "@FUNC_INDEX@", lss.str ());
     1146              l = rld::find_replace (l, "@FUNC_LABEL@", sig.name);
     1147              l = rld::find_replace (l, "@FUNC_DATA_SIZE@", "FUNC_DATA_SIZE_" + sig.name);
    10171148              c.write_line(l);
    10181149            }
     
    10221153              for (size_t a = 0; a < sig.args.size (); ++a)
    10231154              {
    1024                 std::string l = ' ' + generator_.arg_trace;
    10251155                std::string n = rld::to_string ((int) (a + 1));
     1156                l = " " + generator_.arg_trace;
    10261157                l = rld::find_replace (l, "@ARG_NUM@", n);
    10271158                l = rld::find_replace (l, "@ARG_TYPE@", '"' + sig.args[a] + '"');
     
    10521183            if (!generator_.exit_trace.empty ())
    10531184            {
    1054               std::string l = ' ' + generator_.exit_trace;
     1185              l = " " + generator_.exit_trace;
    10551186              l = rld::find_replace (l, "@FUNC_NAME@", '"' + sig.name + '"');
    10561187              l = rld::find_replace (l, "@FUNC_INDEX@", lss.str ());
     
    10611192            if (sig.has_ret () && !generator_.ret_trace.empty ())
    10621193            {
    1063               std::string l = ' ' + generator_.ret_trace;
     1194              std::string l = " " + generator_.ret_trace;
    10641195              l = rld::find_replace (l, "@RET_TYPE@", '"' + sig.ret + '"');
    10651196              l = rld::find_replace (l, "@RET_SIZE@", "sizeof(" + sig.ret + ')');
Note: See TracChangeset for help on using the changeset viewer.