Example #1
0
// receives a number, returns the current CPU use
void send_cpu_response(struct hitArgs *args, char *path, char *request_body)
{
	char tmp[4];
        
	if (args->form_value_counter==1 && !strncmp(form_name(args, 0), "counter", strlen(form_name(args, 0))))
	{
        STRING *response = new_string(32);
        string_add(response, "[");
        for (int p=0; p<max_cpu; p++)
        {
            sprintf(tmp, "%d", usages[p]);
            string_add(response, tmp);
            if (p < max_cpu-1)
            {
                string_add(response, ",");
            }
        }
        string_add(response, "]");
        
        int c = atoi(form_value(args, 0));
        if (c > max_cpu) c=0;
        // TODO: use c if needed
		
        ok_200(args, "\nContent-Type: application/json", string_chars(response), path);
        string_free(response);
	}
	else
	{
		forbidden_403(args, "Bad request");
	}
}
void
DWARFMappedHash::Header::Dump (lldb_private::Stream& strm, const DIEInfo &hash_data) const
{
    const size_t num_atoms = header_data.atoms.size();
    for (size_t i=0; i<num_atoms; ++i)
    {
        if (i > 0)
            strm.PutCString (", ");
        
        DWARFFormValue form_value (NULL, header_data.atoms[i].form);
        switch (header_data.atoms[i].type)
        {
            case eAtomTypeDIEOffset:    // DIE offset, check form for encoding
                strm.Printf ("{0x%8.8x}", hash_data.offset);
                break;

            case eAtomTypeTag:          // DW_TAG value for the DIE
                {
                    const char *tag_cstr = lldb_private::DW_TAG_value_to_name (hash_data.tag);
                    if (tag_cstr)
                        strm.PutCString (tag_cstr);
                    else
                        strm.Printf ("DW_TAG_(0x%4.4x)", hash_data.tag);
                }
                break;

            case eAtomTypeTypeFlags:    // Flags from enum TypeFlags
                strm.Printf ("0x%2.2x", hash_data.type_flags);
                if (hash_data.type_flags)
                {
                    strm.PutCString (" (");
                    if (hash_data.type_flags & eTypeFlagClassIsImplementation)
                        strm.PutCString (" implementation");
                    strm.PutCString (" )");
                }
                break;

            case eAtomTypeQualNameHash:    // Flags from enum TypeFlags
                strm.Printf ("0x%8.8x", hash_data.qualified_name_hash);
                break;

            default:
                strm.Printf ("AtomType(0x%x)", header_data.atoms[i].type);
                break;
        }
    }
}
bool
DWARFMappedHash::Header::Read (const lldb_private::DWARFDataExtractor &data, 
                               lldb::offset_t *offset_ptr, 
                               DIEInfo &hash_data) const
{
    const size_t num_atoms = header_data.atoms.size();
    if (num_atoms == 0)
        return false;
    
    for (size_t i=0; i<num_atoms; ++i)
    {
        DWARFFormValue form_value (NULL, header_data.atoms[i].form);
        
        if (!form_value.ExtractValue(data, offset_ptr))
            return false;
        
        switch (header_data.atoms[i].type)
        {
            case eAtomTypeDIEOffset:    // DIE offset, check form for encoding
                hash_data.offset = (dw_offset_t)form_value.Reference (header_data.die_base_offset);
                break;

            case eAtomTypeTag:          // DW_TAG value for the DIE
                hash_data.tag = (dw_tag_t)form_value.Unsigned ();
                
            case eAtomTypeTypeFlags:    // Flags from enum TypeFlags
                hash_data.type_flags = (uint32_t)form_value.Unsigned ();
                break;

            case eAtomTypeQualNameHash:    // Flags from enum TypeFlags
                hash_data.qualified_name_hash = form_value.Unsigned ();
                break;

            default:
                // We can always skip atoms we don't know about
                break;
        }
    }
    return true;
}