Home | History | Annotate | Line # | Download | only in libsframe.find
plt-findfre-1.c revision 1.1.1.1
      1  1.1  christos /* plt-findfre-1.c -- Test for sframe_find_fre for SFRAME_FDE_TYPE_PCMASK.
      2  1.1  christos 
      3  1.1  christos    Copyright (C) 2023-2024 Free Software Foundation, Inc.
      4  1.1  christos 
      5  1.1  christos    This program is free software; you can redistribute it and/or modify
      6  1.1  christos    it under the terms of the GNU General Public License as published by
      7  1.1  christos    the Free Software Foundation; either version 3 of the License, or
      8  1.1  christos    (at your option) any later version.
      9  1.1  christos 
     10  1.1  christos    This program is distributed in the hope that it will be useful,
     11  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  1.1  christos    GNU General Public License for more details.
     14  1.1  christos 
     15  1.1  christos    You should have received a copy of the GNU General Public License
     16  1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     17  1.1  christos 
     18  1.1  christos #include "config.h"
     19  1.1  christos 
     20  1.1  christos #include <stdlib.h>
     21  1.1  christos #include <string.h>
     22  1.1  christos #include <sys/stat.h>
     23  1.1  christos 
     24  1.1  christos #include "sframe-api.h"
     25  1.1  christos 
     26  1.1  christos /* DejaGnu should not use gnulib's vsnprintf replacement here.  */
     27  1.1  christos #undef vsnprintf
     28  1.1  christos #include <dejagnu.h>
     29  1.1  christos 
     30  1.1  christos static int
     31  1.1  christos add_plt_fde1 (sframe_encoder_ctx *ectx, int idx)
     32  1.1  christos {
     33  1.1  christos   int i, err;
     34  1.1  christos   /* A contiguous block containing 3 FREs.  The start_ip_offset must remain
     35  1.1  christos      less than 16 bytes.  */
     36  1.1  christos   sframe_frame_row_entry fres[]
     37  1.1  christos     = { {0x0, {0x1, 0, 0}, 0x3},
     38  1.1  christos 	{0x6, {0x2, 0xf0, 0}, 0x5},
     39  1.1  christos 	{0xc, {0x3, 0xf0, 0}, 0x4}
     40  1.1  christos       };
     41  1.1  christos 
     42  1.1  christos   unsigned char finfo = sframe_fde_create_func_info (SFRAME_FRE_TYPE_ADDR1,
     43  1.1  christos 						     SFRAME_FDE_TYPE_PCMASK);
     44  1.1  christos   /* 5 pltN entries of 16 bytes each.  */
     45  1.1  christos   err = sframe_encoder_add_funcdesc_v2 (ectx, 0x1000, 16*5, finfo, 16, 3);
     46  1.1  christos   if (err == -1)
     47  1.1  christos     return err;
     48  1.1  christos 
     49  1.1  christos   for (i = 0; i < 3; i++)
     50  1.1  christos     if (sframe_encoder_add_fre (ectx, idx, fres+i) == SFRAME_ERR)
     51  1.1  christos       return -1;
     52  1.1  christos 
     53  1.1  christos   return 0;
     54  1.1  christos }
     55  1.1  christos 
     56  1.1  christos int main (void)
     57  1.1  christos {
     58  1.1  christos   sframe_encoder_ctx *ectx;
     59  1.1  christos   sframe_decoder_ctx *dctx;
     60  1.1  christos   sframe_frame_row_entry frep;
     61  1.1  christos   char *sframe_buf;
     62  1.1  christos   size_t sf_size;
     63  1.1  christos   int err = 0;
     64  1.1  christos   unsigned int fde_cnt = 0;
     65  1.1  christos 
     66  1.1  christos #define TEST(name, cond)                                                      \
     67  1.1  christos   do                                                                          \
     68  1.1  christos     {                                                                         \
     69  1.1  christos       if (cond)                                                               \
     70  1.1  christos 	pass (name);                                                          \
     71  1.1  christos       else                                                                    \
     72  1.1  christos 	fail (name);                                                          \
     73  1.1  christos     }                                                                         \
     74  1.1  christos     while (0)
     75  1.1  christos 
     76  1.1  christos   ectx = sframe_encode (SFRAME_VERSION, 0, SFRAME_ABI_AMD64_ENDIAN_LITTLE,
     77  1.1  christos 			SFRAME_CFA_FIXED_FP_INVALID,
     78  1.1  christos 			-8, /* Fixed RA offset for AMD64.  */
     79  1.1  christos 			&err);
     80  1.1  christos 
     81  1.1  christos   err = add_plt_fde1 (ectx, 0);
     82  1.1  christos   TEST ("plt-findfre-1: Adding FDE1 for plt", err == 0);
     83  1.1  christos 
     84  1.1  christos   fde_cnt = sframe_encoder_get_num_fidx (ectx);
     85  1.1  christos   TEST ("plt-findfre-1: Test FDE count", fde_cnt == 1);
     86  1.1  christos 
     87  1.1  christos   sframe_buf = sframe_encoder_write (ectx, &sf_size, &err);
     88  1.1  christos   TEST ("plt-findfre-1: Encoder write", err == 0);
     89  1.1  christos 
     90  1.1  christos   dctx = sframe_decode (sframe_buf, sf_size, &err);
     91  1.1  christos   TEST("plt-findfre-1: Decoder setup", dctx != NULL);
     92  1.1  christos 
     93  1.1  christos   /* Find the first FRE in PLT1.  */
     94  1.1  christos   err = sframe_find_fre (dctx, (0x1000 + 0x0), &frep);
     95  1.1  christos   TEST("plt-findfre-1: Find first FRE in PLT1",
     96  1.1  christos        ((err == 0) && (sframe_fre_get_cfa_offset (dctx, &frep, &err) == 0x1)));
     97  1.1  christos 
     98  1.1  christos   /* Find the second FRE.  */
     99  1.1  christos   err = sframe_find_fre (dctx, (0x1000 + 0x6), &frep);
    100  1.1  christos   TEST("plt-findfre-1: Find second FRE in PLT1",
    101  1.1  christos        ((err == 0) && (sframe_fre_get_cfa_offset (dctx, &frep, &err) == 0x2)));
    102  1.1  christos 
    103  1.1  christos   /* Find the last FRE.  */
    104  1.1  christos   err = sframe_find_fre (dctx, (0x1000 + 0xc), &frep);
    105  1.1  christos   TEST("plt-findfre-1: Find last FRE in PLT1",
    106  1.1  christos        ((err == 0) && (sframe_fre_get_cfa_offset (dctx, &frep, &err) == 0x3)));
    107  1.1  christos 
    108  1.1  christos   /* Find the first FRE in PLT4.  */
    109  1.1  christos   err = sframe_find_fre (dctx, (0x1000 + 16*3 + 0x0), &frep);
    110  1.1  christos   TEST("plt-findfre-1: Find first FRE in PLT4",
    111  1.1  christos        ((err == 0) && (sframe_fre_get_cfa_offset (dctx, &frep, &err) == 0x1)));
    112  1.1  christos 
    113  1.1  christos   /* Find the second FRE in PLT4.  */
    114  1.1  christos   err = sframe_find_fre (dctx, (0x1000 + 16*3 + 0x6), &frep);
    115  1.1  christos   TEST("plt-findfre-1: Find second FRE in PLT4",
    116  1.1  christos        ((err == 0) && (sframe_fre_get_cfa_offset (dctx, &frep, &err) == 0x2)));
    117  1.1  christos 
    118  1.1  christos   /* Find the last FRE in PLT4.  */
    119  1.1  christos   err = sframe_find_fre (dctx, (0x1000 + 16*3 + 0xc), &frep);
    120  1.1  christos   TEST("plt-findfre-1: Find last FRE in PLT4",
    121  1.1  christos        ((err == 0) && (sframe_fre_get_cfa_offset (dctx, &frep, &err) == 0x3)));
    122  1.1  christos 
    123  1.1  christos   sframe_encoder_free (&ectx);
    124  1.1  christos   sframe_decoder_free (&dctx);
    125  1.1  christos 
    126  1.1  christos   return 0;
    127  1.1  christos }
    128